PHP, Cannot modify header information - headers already sent by?

  • Thread starter Thread starter Liars never lies
  • Start date Start date
L

Liars never lies

Guest
Simply put that code in the top of the PHP file, before any other code or part of the HTML is generated, even before the DTD and XML declaration (if you have them) and definitely before the any HTML code is generated.

Once DTD and XML declaration is generated, it is impossible to modify the header as it is already generated and sent to the browser.
 
I am getting the following error in my PHP code: Cannot modify header Warning: Cannot modify header information - headers already sent by (output started at /var/www/login22.php:9) in /var/www/login22.php on line 170

Warning: Cannot modify header information - headers already sent by (output started at /var/www/login22.php:9) in /var/www/login22.php on line 171

Warning: Cannot modify header information - headers already sent by (output started at /var/www/login22.php:9) in /var/www/login22.php on line 172.

I tried eliminating and white spaces in the code but I am still getting the error.

part of my code where the error is coming from is as follows:

if($DBinfo->password == $_POST['password'])
{
$hour = time() + 3600;
$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0;
setcookie(ID_my_site, $_POST['username'], $hour); // line 170
setcookie(Key_my_site, $_POST['password'], $hour); // line 171

header("Location: memberarea2.php"); // line 172
}
 
The problem is that you're apparently trying to change header information after the page header has been sent to the browser. Once the server sends the header, you can't change anything in it, which would be a massive security hole.

The best way to do this is to use an output buffer. This will allow you to build up what you want to send in a buffer, and make changes to the buffer content before it's flushed out to the client.

Read this:

http://www.php.net/manual/en/book.outcontrol.php

Start at the intro.
 
Back
Top