Welcome! Log In Create A New Profile


Cannot modify header information

Posted by Mariuspienaar 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Cannot modify header information
February 25, 2013 08:58PM
Good day All

Is there any way to disable warnings? when i upload my portfolio to the server(on the net) it works great, that is the orgfree.com one. But when I upload it to my server of mweb,it shows the following warnings when i want to login in:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/m7713830/public_html/login.php:44) in /home/m7713830/public_html/login.php on line 93

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/m7713830/public_html/login.php:44) in /home/m7713830/public_html/login.php on line 93

Warning: Cannot modify header information - headers already sent by (output started at /home/m7713830/public_html/login.php:44) in /home/m7713830/public_html/login.php on line 95
SO line 44 is where my PHP code is starting and line 93 is where my session starts.line 95 points to my line that points to header Location: loggedin.php in the if function when the session is true.

If I do research on this topic i found that the meta char of utf 8 must change to ANSI, utf 8 is putting empty space in the beginning of the file, there's not suppose to be any empty spaces before the <?php code and that the php code MUST be ontop of the page.But i cannot put my php code on top of all the files because some pages must read my HTML code first to design the layout.

But whats also weird is the fact that on the orgfree.com server there are none of these messages and login is working perfectly(but not on my private mweb server confused smiley , it looks like it can be a server issue also?

I will continue doing research.And post my solution here again for those that might come across this same prob.
Re: Cannot modify header information
February 25, 2013 10:53PM
All right, a little bit more info on that warning...quoted by some php forums :
"That error means you outputted something to the browser before line 93 and then tried to use a header value that can't be sent because of course the header had already been sent before line 40".

Yes my header point to another file named loggedin.php. The code on top of that file is just
Language: PHP
<?PHP session_start();   if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) { header ('Location: login.php'); }   ?>
so that a user cannot type the URL straight into the address bar to skip the loggin, but to take them back to the loggin page. The thing is that i cannot see that,that code can make a difference. And I'm definitely not gonna take that code out and make my site vulnerable for attacks.thumbs down
Re: Cannot modify header information
February 26, 2013 07:54AM
Session with a header redirect must be on top of the page before any other code. That is its place. If not logged in, the user should not be able to enter the page at all. No spaces there (use hard breaks to put in a new line).

You must call header() before your script produces any output e.g. echo this or print that is output.

Suppressing the error is not the way to go, because you make your code less portable (as you point out, on one server it is ok on another it is. I'll trust the server that gives an error). Orgfree is sort of gong happy lucky, but then you don't pay for it, also meaning you ill not get the best.
Re: Cannot modify header information
May 10, 2013 09:20AM
Just want to give the solution, yes the problem here was with the PHP code. It was suppose to be on top of all the other code(before html).There should not even be any html or css code before the PHP code.Problem solved.
Sorry, only registered users may post in this forum.

Click here to login