PHP - Moved: Warning: Header May Not Contain More Than A Single Header.. Help!
This topic has been moved to PHP Applications.
http://www.phpfreaks.com/forums/index.php?topic=350027.0 Similar TutorialsHello everyone, I'm just starting out with PHP as I need to create an online bookstore for a school project. I'm working by a magazine which should teach you exactly how to do this using PHP, but I've had a bunch of problems with the code they use and I don't really know what's going on. Anyway, this looks really simple and basically what it does is allows you to post a comment on a book, then returns you to the book's page. Problem is, I'm getting the Header may not contain more than a single header, new line detected. error and I can't figure out why. I've tried researching into the matter but all the cases I found had to do with returning to an url, which is not my case. Anyway, here's the snippet of code: The form: Code: [Select] <div style="width:400px; border:1px solid #ffffff; background-color:#F9F1E7; padding:5px"> <b>Adauga opinia ta:</b> <hr size="1"> <form action="adauga_comentariu.php" method="POST"> Nume: <input type="text" name="nume_utilizator"><br><br> Email: <input type="text" name="adresa_email"><br><br> Comentariu: <br> <textarea name="comentariu" cols="45"></textarea><br><br> <input type="hidden" name="id_carte" value="<?=id_carte?>"> <center><input type="submit" value="Adauga"</center> </form> </div> The script adaugare_comentariu.php: Code: [Select] <?php ob_start(); include("conectare.php"); $numeFaraTags=strip_tags($_POST['nume_utilizator']); $emailFaraTags=strip_tags($_POST['adresa_email']); $comentariuFaraTags=strip_tags($_POST['comentariu']); $sql="insert into comentarii (id_carte, nume_utilizator, adresa_email, comentariu) values(".$_POST['id_carte'].", '".$numeFaraTags."','".$emailFaraTags."','".$comentariuFaraTags."')"; mysql_query($sql); $inapoi="carte.php?id_carte=".$_POST['id_carte']; header("location:urldecode($inapoi)"); ob_end_flush(); ?> conectare.php connects to the mysql database. $inapoi is the variable which returns the user to carte.php (the book he posted a comment on), where id_carte is the book's unique id. I'm getting Header may not contain more than a single header, new line detected on line ten, which is the header line. Can anyone help me? I've been stumped on this for a few days now and I've just let it pass and started working on other bits, but it's bugging me too much and I'd like to fix it. Hi Everyone I am having a few issues with my website. I have developed in on my xampp local host and it works ok but when I upload the files and try to renew a membership using stripe I get the following messages. Warning: session_start(): Cannot start session when headers already sent in /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/inc/settings.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/procedures/payments/charge.php:1) in /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/procedures/payments/charge.php on line 141 I have some includes that appear on every page. This is the bootstrap.php file. This file holds the settings.php which connects to my database and other function files. In this settings page I call the session_start() php function and then connect to my database. I call the bootstrap.php file on every page to there for call the session_start() on every page. I am using sessions alot so is this the right thing to do? I have attached the renew_membership payment page which holds the form. The user fills out the payment page and the form data gets sent to a script called charge.php which uses the stripe objects to make the payment. I then want to do a redirect to the paymentSuccess.php page to output to the user that the payment was made successfully. This is where the issues arrise. I have split the charge file into 3 screen shots so it is more readable. Hope someone can help me. Thanks a lot David
Edited April 26 by Irish_Dave Quote Warning: Cannot modify header information - headers already sent by (output started at /home3/nyhungry/public_html/storeprueba/storescripts/connect_to_mysql.php:2) in /home3/nyhungry/public_html/storeprueba/storeadmin/admin_login.php on line 29 What can I do to fix the error where a second header is called, needed but intervening admin_login.php Code: [Select] <?php session_start(); if (isset($_SESSION["manager"])) { header("location:index.php"); exit(); } ?> <?php if (isset($_POST["username"]) && isset($_POST["password"])) { $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters include "../storescripts/connect_to_mysql.php"; $sql = mysql_query( "SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 1) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; } $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location:index.php"); exit(); } else { echo 'That information is incorrect, try again <a href="index.php">Click Here</a>'; exit(); } } ?> is the second header here like below in the code clashing? because in the connect_to_mysql.php there is no headers Code: [Select] <?php $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location:index.php"); exit(); <? Hello,
I have an error on multiple pages which looks much like this. If anyone can help that would be gratefully appreciated. I would also like to ask if you may give me an explanation as to why it is occurring and not just a solution. Also when I take the second header out the error disappears.
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\blog\blog_display_post.php:47) in C:\xampp\htdocs\blog\comments.php on line 49
Here is my code:
if(strlen($email) > 5){
mysqli_query($con, "INSERT INTO emails (email) VALUES ('$email')"); I understand the warning, but I don't get the issue on my local server, only on my live server. From what I can see in the outputted source is a space and also i'm assuming a newline, before the warning... I've traced every route in my code, no output what-so-ever. I can't believe the hosts would insert such characters. I've tried separate files within the root directory, an html and a php, neither output these characters. Eventually I commented out the inclusion of modules one by one and found that the error should be in a specific one of these... Now going through I can't find any 'echo' or 'print' statements. Everything is within functions, and this error happens before anything is called, just included. There are no erroneous spaces before or after php code tags. What else would / could produce output? (and why no issue on local server?) EDIT: There is no use of 'output buffering' either... I get an error stating that I cannot modify header information when I try to add a title to my login page. Here's <?php session_start(); require_once("includes/dbconn.php"); include("includes/htmlheader.php"); mysql_select_db(center); $user = $_POST['username']; $pass = $_POST['password']; $sql = "select username, password from users"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $isuser = $row['username']; $ispass = $row['password']; if(isset($_POST['submit'])){ if(($user==$isuser)&&($pass==$ispass)) { $_SESSION['username'] = $user; header("Location: home.php"); }else{ echo "Invalid Username or Password"; } } ?> The htmlheader.php has the title string. Help is appreciated Hi All, I just formatted my HD and had a WAMP setup. I have not installed each component separately (newest versions). When I type in a text box and press the submit button, I get: Warning: Cannot modify header information - headers already sent by (output started at D:\Web\Apache\htdocs\projects\tms_new\functions\functions.js:304) in D:\Web\Apache\htdocs\projects\tms_new\apps\index.php on line 167 Line 304 in the functions.js file is: </script> Line 167 in index.php is: header('Location: index.php?lastname='.stripslashes($lastname)); It says I am sending header information before line 167, but there isn't any. The .JS file only has JS code. Can someone give me any suggestions? Thanks everyone!! So last night I was changing the amount of posts I wanted on my Thesis Themed Wordpress blog. I went to click the Save button within wordpress and got this message on the next page. "Warning: Cannot modify header information - headers already sent by (output started at /home/content/50/8403650/html/wp-content/themes/thesis_18/custom/custom_functions.php:2) in /home/content/50/8403650/html/wp-includes/pluggable.php on line 934" Now my nav menu doesn't show up and when I go to archives, it gives me the same warning. Can someone please help me with this? Any help would be appreciated. I've added both custom_functions.php and pluggable.php as an attachment, I don't think it has anything to do with pluggable but added just in case. Thanks for your help. Briannyc [attachment deleted by admin] <?php header('Refresh: 5; URL=http://www.miraculousmedalapostolate.com'); exit(); ?> i dont know what to do with this! i have tried using other hosting and the code was working fine... please help me, i have been stuck on this problem for 2 days now. i have a file connection.php, that contains functions to connect and disconnect from database. the functions are as follows: Code: [Select] <?php //connection.php file function connect() { $con = mysql_connect("localhost","abcd","123456"); if(!$con) die ('Error! could not connect to data to add data'); return $con; } function disconnect($con) { mysql_close($con); } ?> I my intent is to use these functions whenever i would need to connect to database. When i include this file, using include() or require(). I get the warning message, and the page does not redirect to the next page. For example I have created a login page that accepts username and password. The data from this form is "processed" in a login_proc.php file, that redirects the browser to home.php or loginerror.php. But instead of working as I desire, PHP stops with a warning stating the following. Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home1/mintoo/public_html/bew_system/login_proc.php:5) in /home1/mintoo/public_html/bew_system/login_proc.php on line 20 How do I avoid this warning? This is the code in login_proc.php for your reference Code: [Select] <?php //login_proc.php include 'resources/connection.php'; $con= connect(); ob_flush(); $uname = mysql_real_escape_string(strip_tags(substr($_POST['uname'],0,30))); $pass = mysql_real_escape_string(strip_tags(substr($_POST['pwd'],0,30))); $query = "select userid from mintoo_db1.tbl_users where userid='$uname' and password='$pass'"; $result = mysql_query($query); $nofrows = mysql_num_rows($result); disconnect($con); if($nofrows == 0) echo '<h2>Incorrect Username or Password</h2><br/><a href="login.php">Try again</a>'; else if($nofrows == 1) header("location: home.php"); else echo '<h2><u> Error-001:</u>An unexpected error has occured. Please go back and try again after some time or contact system administrator</h2>'; ?> EDIT: Solved it Made the following changes to login_proc.php Code: [Select] <?php ob_start(); include 'resources/connection.php'; $con= connect(); $uname = mysql_real_escape_string(strip_tags(substr($_POST['uname'],0,30))); $pass = mysql_real_escape_string(strip_tags(substr($_POST['pwd'],0,30))); $query = "select userid from mintoo_db1.tbl_users where userid='$uname' and password='$pass'"; $result = mysql_query($query); $nofrows = mysql_num_rows($result); disconnect($con); if($nofrows == 0) echo '<h2>Incorrect Username or Password</h2><br/><a href="login.php">Try again</a>'; else if($nofrows == 1) { header("location: home.php"); } else echo '<h2><u> Error-001:</u>An unexpected error has occured. Please go back and try again after some time or contact system administrator</h2>'; ob_flush(); ?> Hello, Im having a little trouble with this coding I need it to goto this page after an if statement but get this dreaded error Warning: Cannot modify header information - headers already sent by (output started at /home/fightwa1/public_html/fightlivecommentaryrd1.php:15) in /home/fightwa1/public_html/fightlivecommentaryrd1.php on line 57 there are no whitespaces before or after the start and endin <?php, as previously read about. Really struggling with this problem, if anyone can help will be much appreciated. I am getting this error: Warning: Cannot modify header information - headers already sent by on my pvp.php script, this is it: <?PHP include('top.php'); if(!isset($_SESSION['UsersID'])) { echo "You need to be logged into view this page."; include('bottom.php'); exit; } if(isset($_POST['battleplayer'])) { $battleplayer=$_POST['battleplayer']; if($_POST['battlepick']=="username") { $Battling_Result=mysql_query("SELECT * FROM users WHERE Username='$battleplayer'"); $Battling_Rows=mysql_fetch_array($Battling_Result); $battleplayer=$Battling_Rows['ID']; } elseif($_POST['battlepick']=="id") { $Battling_Result=mysql_query("SELECT * FROM users WHERE ID='$battleplayer'"); $Battling_Rows=mysql_fetch_array($Battling_Result); } if(!empty($Battling_Rows)) { $Enemy_ID=$Battling_Rows['ID']; $Enemy_Name=$Battling_Rows['Username']; $Enemy_Level=$Battling_Rows['Level']; $Enemy_HP=$Battling_Rows['HP']; $Enemy_MHP=$Battling_Rows['Max_HP']; $Enemy_Energy=$Battling_Rows['Energy']; $Enemy_MEnergy=$Battling_Rows['Max_Energy']; $Battling_Result2=mysql_query("SELECT * FROM items WHERE Owner='$battleplayer' AND Slot='1'"); $Battling_Rows2=mysql_fetch_array($Battling_Result2); $Battling_Result3=mysql_query("SELECT * FROM items WHERE Owner='$battleplayer' AND Slot='2'"); $Battling_Rows3=mysql_fetch_array($Battling_Result3); $Battling_Result4=mysql_query("SELECT * FROM items WHERE Owner='$battleplayer' AND Slot='3'"); $Battling_Rows4=mysql_fetch_array($Battling_Result4); $Battling_Result5=mysql_query("SELECT * FROM items WHERE Owner='$battleplayer' AND Slot='4'"); $Battling_Rows5=mysql_fetch_array($Battling_Result5); $Battling_Result6=mysql_query("SELECT * FROM items WHERE Owner='$battleplayer' AND Slot='5'"); $Battling_Rows6=mysql_fetch_array($Battling_Result6); $Enemy_Attack1=$Battling_Rows2['Name']; $Enemy_Attack2=$Battling_Rows3['Name']; $Enemy_Attack3=$Battling_Rows4['Name']; $Enemy_Attack4=$Battling_Rows5['Name']; $Enemy_Attack5=$Battling_Rows6['Name']; $Enemy_Power=$Battling_Rows['Power']; $Enemy_Defense=$Battling_Rows['Defense']; $Enemy_Magic=$Battling_Rows['Magic']; $Enemy_Race=$Battling_Rows['Race']; $Enemy_Class=$Battling_Rows['Class']; $Battle_Start="No"; $User_ID=$_SESSION['UsersID']; mysql_query("DELETE from battle_info WHERE User_ID='$User_ID'"); mysql_query("INSERT into battle_info(Enemy_ID, Enemy_Name, Enemy_Level, Enemy_HP, Enemy_MHP, Enemy_Energy, Enemy_MEnergy, Enemy_Attack1, Enemy_Attack2, Enemy_Attack3, Enemy_Attack4, Enemy_Attack5, Enemy_Power, Enemy_Defense, Enemy_Magic, Enemy_Race, Enemy_Class, Battle_Start, User_ID) VALUES('$Enemy_ID', '$Enemy_Name', '$Enemy_Level', '$Enemy_HP', '$Enemy_MHP', '$Enemy_Energy', '$Enemy_MEnergy', '$Enemy_Attack1', '$Enemy_Attack2', '$Enemy_Attack3', '$Enemy_Attack4', '$Enemy_Attack5', '$Enemy_Power', '$Enemy_Defense', '$Enemy_Magic', '$Enemy_Race', '$Enemy_Class', '$Battle_Start', '$User_ID')") or die(mysql_error()); header('Location: battle.php'); } else { echo "This user does not exist.<br />"; echo "Enter the Username/ID of the person you want to battle below:"; echo "<br /><form method='POST'><input type='text' name='battleplayer'><select name='battlepick'><option value='username'>Username</option><option value='id'>ID</option></select>"; echo "<br /><input type='submit' name='Submit' id='Submit' value='Submit' onclick='this.disabled=true; this.form.submit;'>"; echo "</form>"; } } else { echo "Enter the Username/ID of the person you want to battle below:"; echo "<br /><form method='POST'><input type='text' name='battleplayer'><select name='battlepick'><option value='username'>Username</option><option value='id'>ID</option></select>"; echo "<br /><input type='submit' name='Submit' id='Submit' value='Submit' onclick='this.disabled=true; this.form.submit;'>"; echo "</form>"; } include('bottom.php'); ?> and this is my top.php script: <?PHP include('connect.php'); $ID = $_SESSION['UsersID']; $ID = mysql_real_escape_string($ID); if (!isset($_SESSION['UsersID'])) { echo " <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> <font face='verdana'> <head> <link rel='stylesheet' type='text/css' href='style.css'> </style> </head> <title>Shadow of the Eternal - Text Based RPG</title> <body> <div id='banner'><a href='index.php'><img src='banner.png'></a></div> <div id='quicklinks'>Test</div> <div id='leftmenu'> <ul> <li>Main <ul> <li><a href='index.php'>Home</a></li> <li><a href='login.php'>Login</a></li> <li><a href='signup.php'>Sign Up</a></li> </ul> </li> </ul></div> <div id='content'> </font>"; } else { echo " <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> <font face='verdana'> <head> <link rel='stylesheet' type='text/css' href='style.css'> </style> </head> <title>Shadow of the Eternal - Text Based RPG</title> <body> <div id='banner'><a href='index.php'><img src='banner.png'></a></div> <div id='quicklinks'>Test</div> <div id='leftmenu'> <ul> <li>CryptoWare <ul> <li><a href='http://furiousflash.com'>Furious Flash</a></li> <li><a href='http://crypto-ware.com'>CryptoWare</a></li> </ul> </li> <li>Main <ul> <li><a href='index.php'>Home</a></li> <li><a href='viewcomments.php'>News Comments</a></li> <li><a href='logout.php'>Logout</a></li> <li><a href='http://furiousflash.com/forum'>Forums</a></li> </ul> </li> </ul></div> <div id='content'> </font>"; } ?> And just in case this is my connect.php script: <?PHP mysql_connect('localhost','*****','*****'); mysql_select_db('*****'); session_start(); ?> Any idea why? I am having a problem with my login page when I set cookies I get this error. Quote Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 66 Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 67 Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 68 Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in loginform.php on line 72 I do have ob_start() at the beginning and ob_flush() and the end but i still get the error <?phpinclude('config.php');ob_start();@session_start();if (!isset($_POST['login'])) {?><form method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <fieldset> <legend>Login</legend> <table> <tr> <td>Email </td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Password </td> <td><input type="password" name="password" /></td> </tr> <tr> <td><input type="submit" name="login" value="Login" /></td> </tr> <tr> <td><a href="<?=$siteurl?>/register.php">Register</a></td> </tr> </table> </fieldset></form><?php}else{ //Declare some variables $email = secure($_POST['email']); $password = secure($_POST['password']); //Check if the form is filled out if (!$email || !$password) { echo 'Please fill out the form completely'; echo '<a href="'. $siteurl .'/login.php">Go Back</a>'; } else { $user = mysql_query("SELECT * FROM `users` WHERE email = '$email'"); if (! mysql_num_rows($user)) { echo 'That user doe not exist'; } else { //Encrypt the password $encpass = sha1($password . $salt); //Find the user $superquery = mysql_query("SELECT * FROM `users` WHERE email = '$email' AND password = '$encpass'"); if (mysql_num_rows($superquery) == 1) { //If the user is found, set the cookies setcookie("username", $email, 0); setcookie("password", $encpass, 0); setcookie("is_logged_in", true, 0); //send the user to the home page header("Location: " . $siteurl . "members.php"); } else { echo 'Password was incorrect. Please try again.'; } } }}ob_flush();?>() what am i doing wrong? This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321255.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=321605.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=320768.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=355345.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=328141.0 Hi there, I have a form which displays a "successful" message if the form is completed correctly. However, I want the form to go to another url if it is successful. I have tried this, but I get the "headers already sent..." message // Add New Subscriber Success Message $successMsg = header('Location: http://www.example.com/'); is there another way to forward onto another page? Thanks Hi everyone, I have a login area, and i also have set up for me is a view page... the view page is each user's sort of profile, it gets id and displays relevant content. i was wondering if i could get the id or post rather through a re-direct on log in? for example user logs in with username and password, user is re-directed to the view page like this: header( "refresh:5;url=view00=id.php " ); echo '<h1>You will be re-directed in 5 seconds...</h1>'; user is taken to view page where they can edit bit on it. So far though i'm getting page not found error? first of all is this possible? if not whats the correct way/better way? Thanks |