Community Page
- www.tech-recipes.com/ Jump to website »
-
Subscribe -
Community
-
Top Commenters
-
Popular Threads
-
Recent Comments
- Please completely delte my MySpace Profile with all information. I do understand that this will be permanent...
- Thank you! This was very helpful.
- Opps I didn't see lift chair... "The 'gcc compiler' is installed when one installs 'XcodeTools' (via the 'XcodeTools.mpkg' file) from the installation CD (if...
- Sorry if i am repeating anyone but I know if you have mac 10.4.X then on the install disk you can find a copy of xcode...
- ok
Tech-Recipes
Cookbook of Tech TutorialsSolve PHP error: Cannot modify header information - headers already sent | PHP programming | Tech-Recipes
Started by qdideas · 9 months ago
8 months ago
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.
3 months ago
1 month ago
1 month ago
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.
1 month ago
1 year ago
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
1 year ago
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
1 year ago
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.
4 months ago
10 months ago
I am baffled. These are hard to solve sometimes.
Dave
10 months ago
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!
10 months ago
Dave
8 months ago
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
error_reporting (E_ALL);
8 months ago
the lines that prints out the error are on my setcookie() events.
8 months ago
just wanted to broaden the horizon on problems that generate this error output
8 months ago
8 months ago
#3 solved my problem! :)
7 months ago
7 months ago
Thanks
7 months ago
Take care
Problend
6 months ago
<?php
......
?>
all i had to do was
<?php
......
?>
can you not the difference? i couldnt either :(
6 months ago
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!
6 months ago
5 months ago
5 months ago
<?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.
5 months ago
Amazing what some additional unnoticed whitespace can cause havoc
sometimes.
4 months ago
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..
4 months ago
if (!$result) {
die('Invalid query: ' . mysql_error());
}
Dumping the error message may help in this case, too.
Good luck!
4 months ago
4 months ago
Thanks
4 months ago
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.
3 months ago
2 months ago
2 months ago
2 months ago
There should be no print , no echo and no spaces before or after header statement.
1 month ago
i have been working on the same for the past 5 days........... the error i had was a space before PHP tag..
1 month ago
Thank you!
4 weeks ago
3 weeks ago
3 weeks ago
Thanks for the easy instructions!
2 weeks ago
Thanks!
2 weeks ago
This is really a culprit.
Thanks for help.
1 week ago
2 days ago
Cheers