Carlton Posted July 25, 2010 Share Posted July 25, 2010 I'm getting this strange error everytime I add a cookie, I did search it on google, but no headers were matching the cookie. Warning: Cannot modify header information - headers already sent by (output started at url) in url on line 25 url is obviously a replacement for the original error spot, the error line is below. setcookie ("Epic-Missions", $escape2,time()+3600) or die('Make sure you have cookies enabled!'); The make sure you have cookies enabled show also, any clue what's wrong? Quote Link to comment https://forums.phpfreaks.com/topic/208852-header-error/ Share on other sites More sharing options...
wildteen88 Posted July 25, 2010 Share Posted July 25, 2010 You have some form of output which is causing the error. You should note anything outside of your <?php ?> tags is considered output, and also when you're echoing/printing etc. In order to solve this you need to find out where the output is comming from. This is actually given to you within the error message, eg Warning: Cannot modify header information - headers already sent by (output started at YOUR URL HERE:LINE NUMBER IS GIVEN HERE ON FIRST INSTANCE OF OUTPUT) in url on line 25 However you have sensored too much information for me to tell you where the output is. Quote Link to comment https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090965 Share on other sites More sharing options...
Pikachu2000 Posted July 25, 2010 Share Posted July 25, 2010 The error is pretty self-explanatory. You can't send anything to the browser, not even whitespace, before sending headers. Something on line 25 is outputting to the browser, and setcookie() comes after line 25, correct? Quote Link to comment https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090967 Share on other sites More sharing options...
Carlton Posted July 25, 2010 Author Share Posted July 25, 2010 The error is pretty self-explanatory. You can't send anything to the browser, not even whitespace, before sending headers. Something on line 25 is outputting to the browser, and setcookie() comes after line 25, correct? No, after line 25 includes: echo("<html><meta HTTP-EQUIV='REFRESH' content='0; url=ucphome.php?page=ucp'></html>"); You have some form of output which is causing the error. You should note anything outside of your <?php ?> tags is considered output, and also when you're echoing/printing etc. In order to solve this you need to find out where the output is comming from. This is actually given to you within the error message, eg Warning: Cannot modify header information - headers already sent by (output started at YOUR URL HERE:LINE NUMBER IS GIVEN HERE ON FIRST INSTANCE OF OUTPUT) in url on line 25 However you have sensored too much information for me to tell you where the output is. The line number i'm guessing you're asking for in the "LINE NUMBER IS GIVEN HERE..." is below. $server = mysql_connect($HOST,$USER, $PASSWORD) OR DIE ('Unable to connect to database! Please try again later.'); Quote Link to comment https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090969 Share on other sites More sharing options...
Pikachu2000 Posted July 25, 2010 Share Posted July 25, 2010 Paste in the code, from the beginning to about line 40. Change any passwords/database credentials before posting it . . . Quote Link to comment https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090972 Share on other sites More sharing options...
Carlton Posted July 25, 2010 Author Share Posted July 25, 2010 Paste in the code, from the beginning to about line 40. Change any passwords/database credentials before posting it . . . <!-- PHP Basic Script Includes --> <?php include("MySQL.php"); ?> <?php include("ScriptBegin.php"); ?> <!-- PHP Include Header --> <?php include("header.php"); ?> <!-- Content --> <!-- content begins --> <div id="content"> <div id="right"> <h2>UCP</h2> <div class="text"> <p><span>UCP</span> </p> <p> <?php $escape = mysql_real_escape_string($_POST['password']); $escape2 = mysql_real_escape_string($_POST['username']); $query = mysql_query("SELECT * FROM Accounts WHERE Name ='" . $escape2 . "' AND Password = md5(sha1('" . $escape . "'))") or die('Cannot Execute:'. mysql_error()); $amount = mysql_num_rows($query); if($amount > 0) { setcookie ("Epic-Missions", $escape2,time()+3600) or die('Make sure you have cookies enabled!'); echo("<html><meta HTTP-EQUIV='REFRESH' content='0; url=ucphome.php?page=ucp'></html>"); } else { echo("<html>Your username or password is incorrect, click <a href='UCP.php'>here</a> to try again.<br /></html>"); } ?></p> </div> <div></div> </div> <?php include("Top20.php"); ?> </div> <!-- PHP Footer Includes --> <?php include("Footer.html"); ?> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090974 Share on other sites More sharing options...
Pikachu2000 Posted July 25, 2010 Share Posted July 25, 2010 Output to the browser starts on the very first line. The setcookie() is after that. Nothing at all can be sent to the browser before sending headers. Read the (at least) first paragraph of the PHP manual for setcookie(). Quote Link to comment https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.