| | |
PHP Warning: Cannot modify header information - headers already sent by (output .....
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2007
Posts: 66
Reputation:
Solved Threads: 0
PHP Warning: Cannot modify header information - headers already sent by (output .....
0
#1 Sep 4th, 2007
Hello please help me troubleshooting this. i got this error in my login.. pleaaaaase. below is the error that prompts me when i login:
PHP Warning: Cannot modify header information - headers already sent by (output started at D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php:9) in D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php on line 71 PHP Warning: Cannot modify header information - headers already sent by (output started at D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php:9) in D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php on line 72 PHP Warning: Cannot modify header information - headers already sent by (output started at D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php:9) in D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php on line 75
Here is my code: please tell me what's going wrong. thanks.
<?php
// Connects to your Database
mysql_connect("spindev.spinweb.ph", "spindev_ypsuser", "yps123") or die(mysql_error());
mysql_select_db("spindev_ypsnew") or die(mysql_error());
//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{ header("Location: login.php");
}
//otherwise they are shown the admin area
else
{
echo "Admin Area<p>";
echo "Your Content<p>";
echo "<a href=logout.php>Logout</a>";
}
}
}
else
//if the cookie does not exist, they are taken to the login screen
{
header("Location: login.php");
}
?>
PHP Warning: Cannot modify header information - headers already sent by (output started at D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php:9) in D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php on line 71 PHP Warning: Cannot modify header information - headers already sent by (output started at D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php:9) in D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php on line 72 PHP Warning: Cannot modify header information - headers already sent by (output started at D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php:9) in D:\HostingSpaces\spindev\spindev.spinweb.ph\wwwroot\YPS\login\login.php on line 75
Here is my code: please tell me what's going wrong. thanks.

<?php
// Connects to your Database
mysql_connect("spindev.spinweb.ph", "spindev_ypsuser", "yps123") or die(mysql_error());
mysql_select_db("spindev_ypsnew") or die(mysql_error());
//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{ header("Location: login.php");
}
//otherwise they are shown the admin area
else
{
echo "Admin Area<p>";
echo "Your Content<p>";
echo "<a href=logout.php>Logout</a>";
}
}
}
else
//if the cookie does not exist, they are taken to the login screen
{
header("Location: login.php");
}
?>
Re: PHP Warning: Cannot modify header information - headers already sent by (output .
0
#2 Sep 4th, 2007
From first glance it looks like you've placed echo above the header location script.
Headers must be parsed before any HTML, and for some reason (Unknown by me, but I'm sure others can answer why) certain hosts don't like it when you place any HTML above header tags.
I would stick the HTML below the php code, specifically below the Header("Location: login.php") script.
Eg:
I could be completely off the mark, since it is late. I'd suggest tweaking the order of your conditions so that if an error occurs the user is directed away from the page, otherwise the html at the end loads on a successful log in.
Headers must be parsed before any HTML, and for some reason (Unknown by me, but I'm sure others can answer why) certain hosts don't like it when you place any HTML above header tags.
I would stick the HTML below the php code, specifically below the Header("Location: login.php") script.
Eg:
php Syntax (Toggle Plain Text)
<?php // Connects to your Database mysql_connect("spindev.spinweb.ph", "spindev_ypsuser", "yps123") or die(mysql_error()); mysql_select_db("spindev_ypsnew") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { //echo "Admin Area<p>"; //echo "Your Content<p>"; //echo "<a href=logout.php>Logout</a>"; } } } else //if the cookie does not exist, they are taken to the login screen { header("Location: login.php"); } ?> <h1>Admin Area</h1> <p>Your content</p> <p><a href="logout.php">Logout</a>
Re: PHP Warning: Cannot modify header information - headers already sent by (output .
1
#3 Sep 4th, 2007
•
•
Join Date: May 2007
Posts: 66
Reputation:
Solved Threads: 0
Re: PHP Warning: Cannot modify header information - headers already sent by (output .....
0
#4 Sep 4th, 2007
•
•
Join Date: Sep 2007
Posts: 9
Reputation:
Solved Threads: 0
Re: PHP Warning: Cannot modify header information - headers already sent by (output .
0
#5 Sep 11th, 2007
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
Re: PHP Warning: Cannot modify header information - headers already sent by (output .
0
#6 Feb 19th, 2008
•
•
•
•
try placing this at the top of your page:
<? ob_start(); ?>
then at the bottom of the page place this line of code:
<? ob_flush(); ?>
Thank you so much JeniF. I have been receiving a similar error for days now, and have been unable to complete a class assignment. Popped your suggestion in, and it now works. My elation is directly correlated to my previous frustration, and I just wanted to take the time to say thanks. Have a good one.
(Incidentally, if you get the time, what exactly is the recommended code doing?)
Re: PHP Warning: Cannot modify header information - headers already sent by (output .....
0
#7 Feb 19th, 2008
•
•
Join Date: May 2008
Posts: 1
Reputation:
Solved Threads: 0
Re: PHP Warning: Cannot modify header information - headers already sent by (output .....
0
#8 May 19th, 2008
I had a problem with the "headers already sent" too at my http://www.maxi-pedia.com website. In my case, it was caused by a blank line at the beginning of one *.inc file. PHP seems to have problems with extra spaces here and there.
Check all your *.inc files to make sure you do not have closing ?> in any of them. Closing ?> is not needed in your *.inc files. Check all your *.php files to make sure you do not have blank lines at the beginning or at the end.
If you are working in a CMS, then it may be caused by some module, disable your modules one by one to find out which one causes this.
This can also be caused by UTF-8. If you have your website coded in ASCII and are saving your php files as UTF-8, it can cause this message. If your website and DB are UTF-8, you should be ok with saving php files as UTF-8 though.
Btw, this error message is related to output_buffering on/off in your php.ini. If you have output_buffering set to some cache, the server will allow to send headers with delay (or to modify them shortly after they are sent), and this error will not be tripped. But if you set output_buffering to 0 or not at all, then headers can be sent at only one moment, and if you have some bad code, it will trip this error message.
Check all your *.inc files to make sure you do not have closing ?> in any of them. Closing ?> is not needed in your *.inc files. Check all your *.php files to make sure you do not have blank lines at the beginning or at the end.
If you are working in a CMS, then it may be caused by some module, disable your modules one by one to find out which one causes this.
This can also be caused by UTF-8. If you have your website coded in ASCII and are saving your php files as UTF-8, it can cause this message. If your website and DB are UTF-8, you should be ok with saving php files as UTF-8 though.
Btw, this error message is related to output_buffering on/off in your php.ini. If you have output_buffering set to some cache, the server will allow to send headers with delay (or to modify them shortly after they are sent), and this error will not be tripped. But if you set output_buffering to 0 or not at all, then headers can be sent at only one moment, and if you have some bad code, it will trip this error message.
•
•
Join Date: Feb 2009
Posts: 1
Reputation:
Solved Threads: 0
Re: PHP Warning: Cannot modify header information - headers already sent by (output .
0
#9 Feb 11th, 2009
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
Re: PHP Warning: Cannot modify header information - headers already sent by (output .
0
#10 Jul 3rd, 2009
•
•
•
•
try placing this at the top of your page:
<? ob_start(); ?>
then at the bottom of the page place this line of code:
<? ob_flush(); ?>
Thanks, JeniF!! And thanks DaniWeb!
John
![]() |
Similar Threads
- Warning: Cannot modify header information (PHP)
- Cannot modify header information.Headers already sent (PHP)
- How to solve header - error -PHP (PHP)
- URL Redirection in PHP (PHP)
- PHP Error (PHP)
- header information error (PHP)
- Php newsletter error (PHP)
- PHP Form mailing troubles (PHP)
Other Threads in the PHP Forum
- Previous Thread: Greeting the Guests & Users
- Next Thread: Array Problem
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube






