-
Website
http://www.tech-recipes.com/ -
Original page
http://www.tech-recipes.com/rx/1489/solve-php-error-cannot-modify-header-information-headers-already-sent/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
davak
83 comments · 1 points
-
Web Design
3 comments · 1 points
-
danishbacker
9 comments · 1 points
-
flexinfo
11 comments · 1 points
-
Tonychelle
4 comments · 1 points
-
-
Popular Threads
-
Facebook: How To Get Only Status Updates on Your FB Home Page
1 week ago · 4 comments
-
Firefox: Enable Case Sensitive Searches When Using Find (Ctrl+F)
5 days ago · 1 comment
-
Windows 7: How To Disable Live Preview for Taskbar Thumbnails
1 week ago · 2 comments
-
Gmail: How to block a sender from your inbox
3 weeks ago · 3 comments
-
Our first iPhone game GreenThumb available in the App Store
3 weeks ago · 2 comments
-
Facebook: How To Get Only Status Updates on Your FB Home Page
I have had this problem, however, no white spaces or whatsoever prior <?php tag. I was really frustrated as the file contained only one line <?php header("Location: /subdir/index.php");?> and this was not working as expected.
The issue turned out to be that the file was a UTF-8 encoded file with BOM signature. This was causing the file header to be transferred prior the content has been processed, and therefore I have had the cannot modify headers error.
Please check your files encoding as well as if it seems to you there is no error in your script.
what if you need your PHP file to be UTF8 because you need non-ANSI characters in your script defined strings?
My UTF8 .php file works fine on Windows 5.2.5, but barfs on a linux build of same version.
Sigh.
You run the code. It is stuck somewhere. You set display_errors=On (in php.ini or somewhere else) and run again. This time is shows some Notice then it is stuck at the point where there is a call for header function and displays this "Warning: Cannot modify header information - headers already sent by (output ...". You are thinking this is the bug you have to fix and try this and that. You are WRONG. Your bug is somewhere else past the header function.
When you run the code with display_errors=On and when you see the first Notice about something, the browser already got the header to display the Notice and cannot change the header in the header function which follows after the Notice(s).
That means you cannot see any errors past a header function with display_errors=On and there are some notice(s) you wish to ignore.
The solution is resolve all the notices prior to that warning or keep the display_errors=Off and see the error log to find the real problem. Thanks
i do consider this as a bug. Setting display_error = Off only hides the message error from the user's GUI. And still your header('location: xxx.php') wont work. If you dont have much time tracing your scripts, try this solution:
output_buffering = 4096
good day
i do consider this as a bug. Setting display_error = Off only hides the message error from the user's GUI. And still your header('location: xxx.php') wont work. If you dont have much time tracing your scripts, try this solution:
output_buffering = 4096
good day</ul>
Get rid of the white space before and after <?php ?> tag, it works.
this error can be for different reasons....
I am baffled. These are hard to solve sometimes.
Dave
then it may be a little tougher, but at least it's something.
One additional tip is to exclude the final ?> tag in a file. This tag isn't necessary and if it isn't present, then there cannot be any whitespace after it.
Good luck!
Dave
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
error_reporting (E_ALL);
the lines that prints out the error are on my setcookie() events.
just wanted to broaden the horizon on problems that generate this error output
#3 solved my problem! :)
Thanks
Take care
Problend
<?php
......
?>
all i had to do was
<?php
......
?>
can you not the difference? i couldnt either :(
I had all my php code before the HEAD without any whitespace. (you can't imagine how many times I pressed the delete key trying to get rid of white space that wasn't there :)
Anway, the culprit was that Dreamweaver saved the .php file as as a UTF-8 format file (I had renamed it from a UTF .html file .. so it's really my fault).
When a .php file is saved as UTF it inserts a
line break before everything, but it will be invisible in Dreamweaver.
What you have to do is open the .php file in notepad, and 'Save as' ANSI.
And now, you're good to go!
<?php
......
header("location:../first.php");
?>
then it is working properly.
I've got a line with echo before the header, and got the same warning - Cannot modify header information - headers already sent.
This is happening on a linux environment, on windows (+Apache+mysql) I've got no such a messages, well, I didn't compared those two php.ini properly.
Anyway, thanks for help.
Amazing what some additional unnoticed whitespace can cause havoc
sometimes.
please help me.. please please please.
please take a look at the following script:
it is giving the following errors
---------------------------------------------------------------------------------------
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/compkcom/public_html/cmpanel/check_login.php on line 11
Warning: Cannot modify header information - headers already sent by (output started at /home/compkcom/public_html/cmpanel/check_login.php:11) in /home/compkcom/public_html/cmpanel/check_login.php on line 19
---------------------------------------------------------------------------------------
here goes the php script
----------------------------------------------------------------------------------------------------
<?php session_start();
if((isset($_POST['username'])&&$_POST['username']!="")&&(isset($_POST['password'])&&$_POST['password']!="")){
$error='';
$conn = mysql_connect('localhost','compkcom_care','ptk')or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB,$conn);
$query = "SELECT COUNT(username) AS record FROM admin WHERE username ='" . $_POST['username']."' AND password = '".$_POST['password']."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if($row['record']==1){
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
header("location:welcome.php");
}
else{
$error .="Please+Enter+Correct+Username+and+password%21%0D%0A";
header("location:index.php?&error=".$error);
}
}
else{
$error .="Please+Enter+the+Username+and+password+First%21%0D%0A";
header("location:index.php?&error=".$error);
}
?>:
----------------------------------------------------------------------------------------------------
this script is running fine on my local windows server but giving the above mentioned errors on my linux hosted server..
Please help me...
Thanks..
if (!$result) {
die('Invalid query: ' . mysql_error());
}
Dumping the error message may help in this case, too.
Good luck!
Thanks
http://php.net/manual/en/function.header.php
It is related to earlier versions of PHP, or to setup in php.ini
I've put on the very first line:
<?php
ob_start();
session_start();
?>
Now, everything works fine, i-e you can have more than one header in your code.
There should be no print , no echo and no spaces before or after header statement.
i have been working on the same for the past 5 days........... the error i had was a space before PHP tag..
Thank you!
Thanks for the easy instructions!
Thanks!
This is really a culprit.
Thanks for help.
Cheers
you can solve the problem of "Header already sent" by removing all print and echo statements.
If its still does not work add ob_start() at the start of your file.It will work
I had white spaces in my include files.
Hours upon hours of frustration and headaches.
Thank you. <3333333333
header("location: zodiac.php");
?>
above one is my index.php
and i m trying to redired to zodia.php
here what could be the problem
say i m just redirecting and nothing else
I got the problem,.. anyway thanks for all
I got the problem,.. anyway thanks for all
Thanks for the post