Warning: Cannot modify header information - headers already
Moderator: General Moderators
Warning: Cannot modify header information - headers already
Good evening.
I create a php login with MySQL in Windows XP and when i shift it to an ubuntu server, when i'm trying to connect the browser shows me "Warning: Cannot modify header information - headers already sent".
I used session_register() and setcookie() and both show the same warning!
Is there any way of secure login without using session or cookies?
Thank you very much!
Best regards,
Zinon
I create a php login with MySQL in Windows XP and when i shift it to an ubuntu server, when i'm trying to connect the browser shows me "Warning: Cannot modify header information - headers already sent".
I used session_register() and setcookie() and both show the same warning!
Is there any way of secure login without using session or cookies?
Thank you very much!
Best regards,
Zinon
Re: Warning: Cannot modify header information - headers already
The error message also details the file and line number where output is being sent. Should be an easy fix.
Re: Warning: Cannot modify header information - headers already
It shows me the line of the setcookie(), header() and session_register() in the php file.
Re: Warning: Cannot modify header information - headers already
Might as well post it 
Re: Warning: Cannot modify header information - headers already
I'm really sorry, but i got this warning on other's person computer and i don't have the exact string.
I looking for a solution in order to use it tomorrow
I looking for a solution in order to use it tomorrow
Re: Warning: Cannot modify header information - headers already
Sounds like your out of luck. How are you going to fix code you don't have access to?
Re: Warning: Cannot modify header information - headers already
Heh. I'm trying to find any possible solution to use it tommorrow on that computer, in order not to lose much time as today.
Any help is welcome
Any help is welcome
Re: Warning: Cannot modify header information - headers already
You cannot have any output before setcookie(), header() or session_register(). This means no html, no blank spaces, no php errors, nothing can be sent before you send data. Once you send data the headers are sent to the browser and cannot be modified.
Re: Warning: Cannot modify header information - headers already
Thank you very much!astions wrote:You cannot have any output before setcookie(), header() or session_register(). This means no html, no blank spaces, no php errors, nothing can be sent before you send data. Once you send data the headers are sent to the browser and cannot be modified.
I have these before setcookie():
Code: Select all
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");Re: Warning: Cannot modify header information - headers already
Only if the connection fails, then it would. If you have blank space before your <?php tag, that would be considered output.
Re: Warning: Cannot modify header information - headers already
Oh ok, thank you very very much.astions wrote:Only if the connection fails, then it would. If you have blank space before your <?php tag, that would be considered output.
Another one question please.
If i have a blank space after the ?> tag, does this consider as an output?
I mean i have something like:
Code: Select all
<?php
?>
<html>
</html>Code: Select all
<?php
?><html>
</html>Re: Warning: Cannot modify header information - headers already
Both of your examples sent output.
You cannot do this:
It must be like this:
You cannot do this:
Code: Select all
<?php
# code here
?>
<html>
...
<?php
header("Location: foo");
Code: Select all
<?php
header("Location: foo");
?>
<html>
...
Re: Warning: Cannot modify header information - headers already
Thank you very much from the bottom of my heart!
I appreciate your help!!
I appreciate your help!!
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Warning: Cannot modify header information - headers already
Simply put, the header() can be called only if you have not outputted anything. That is, echo(), print() and stuff outside PHP-tags can't exist before header() calls or you will get that ugly warning.
Re: Warning: Cannot modify header information - headers already
Good evening!!
Guys thank you very much from the bottom of my heart!
You are really helpfull!
astions once again I am under necessity to thank you! Finally, today my script worked thanks to you!
Have a nice day!
Sincerely yours,
Zinonas
Guys thank you very much from the bottom of my heart!
You are really helpfull!
astions once again I am under necessity to thank you! Finally, today my script worked thanks to you!
Have a nice day!
Sincerely yours,
Zinonas