Manixat Posted November 10, 2012 Share Posted November 10, 2012 Hey guys, So I have this really tricky problem with my login system. I get the cannot modify header information but I havent sent any output ? Here's the error log: [10-Nov-2012 09:38:25 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/sdelkata/public_html/login.php:1) in /home/sdelkata/public_html/login.php on line 16 [10-Nov-2012 09:38:25 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/sdelkata/public_html/login.php:1) in /home/sdelkata/public_html/login.php on line 17 and here's the login.php ( lines 16 and 17 are originally the setcookie lines ) <?php ob_start(); require("connect_db.php"); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $msg=""; if (mysql_num_rows(mysql_query("SELECT `id` FROM `blabla` WHERE `email`='$email'"))==0){ $msg = "There is no user named ".wordwrap($email, 33, "<br />\n", 1); }elseif(mysql_num_rows(mysql_query("SELECT `id` FROM `blabla` WHERE `email`='$email' AND BINARY `password`='$password'"))==0){ $msg = "Wrong password!"; }else{ $id = mysql_result(mysql_query("SELECT `id` FROM `blabla` WHERE `email`='$email' AND `password`='$password'"),0); setcookie("dd", md5($id),time()+60*60*24*365*10); setcookie("ff", md5("1"), time()+60*60*24*365*10); sleep(2); echo "<script>document.location.reload(true)</script>"; } if($msg!=""){ sleep(2); echo "<div id='msgboxred'>$msg</div>"; include "login.html"; } ob_end_clean(); ?> I even added ob_start and ob_end_clean but it still gives me the error. What is weird tho is that it works on my 5.4.4 localhost testing server but doesn't work on the online hosting machine which has 5.3.15 ( php version ). Any help is really appreciated! Link to comment https://forums.phpfreaks.com/topic/270530-cannot-modify-header-information-cookies/ Share on other sites More sharing options...
Manixat Posted November 10, 2012 Author Share Posted November 10, 2012 okay a little update, all files which have headers modification give me this same error and it always says the headers are sent at line 1 which is always just "<?php". I tried moving the opening php tag a few lines down and the error was at the opening tag again ? Is this a known issue because I don't seem to find where the problem is ? Even this: <?php header("Content-Type:text/html;charset=utf-8"); Is giving me this: [10-Nov-2012 14:03:07 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/sdelkata/public_html/adsubmit.php:1) in /home/sdelkata/public_html/adsubmit.php on line 3 Link to comment https://forums.phpfreaks.com/topic/270530-cannot-modify-header-information-cookies/#findComment-1391508 Share on other sites More sharing options...
Pikachu2000 Posted November 10, 2012 Share Posted November 10, 2012 There's a sticky topic in this forum titled HEADER ERRORS - READ HERE BEFORE POSTING THEM. Pay attention to the part about byte order mark (BOM). Link to comment https://forums.phpfreaks.com/topic/270530-cannot-modify-header-information-cookies/#findComment-1391512 Share on other sites More sharing options...
PFMaBiSmAd Posted November 10, 2012 Share Posted November 10, 2012 And after you correct how your editor is saving the files, remove the ob_start and ob_end_clean statements from your code. They don't have anything to do with fixing this problem. Also, go into your php.ini on your development system and turn off the output_buffering setting so that your development system matches your live site and you won't waste more time developing php code that won't work when you put it onto your live site. Link to comment https://forums.phpfreaks.com/topic/270530-cannot-modify-header-information-cookies/#findComment-1391515 Share on other sites More sharing options...
Manixat Posted November 10, 2012 Author Share Posted November 10, 2012 There's a sticky topic in this forum titled HEADER ERRORS - READ HERE BEFORE POSTING THEM. Pay attention to the part about byte order mark (BOM). Dear god, I've read the whole thing except the last post assuming that the answer wont be there, unfortunately murphy's laws are strongly enforced! Thank you Pikachu2000! Link to comment https://forums.phpfreaks.com/topic/270530-cannot-modify-header-information-cookies/#findComment-1391516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.