"Warning:Cannot modify header information -" Error

This is a discussion on "Warning:Cannot modify header information -" Error within the PHP General forums, part of the PHP Programming Forums category; Hi All ! I am having some problem with the code below. Everytime I run it it gives me the following ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-15-2008
Tiji varghese
 
Posts: n/a
Default "Warning:Cannot modify header information -" Error

Hi All !
I am having some problem with the code below. Everytime I run it it gives me the following error:
Warning: Cannot modify header information - headers already sent
by (output started at
C:\xampp\htdocs\practice.com\displayUserData.php:7 ) in C:\xampp\htdocs\practice.com\displayUserData.php on line 12

The source code of the page is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
</head>
<body>
<?php $textColor = $_POST["TextColor"];
$boldText = $_POST["boldText"];
$userComments = stripslashes($_POST['userComments']);
if(isset($_POST["saveInfo"]))
{
setcookie("userData",$userComments,time()+60*60*24 *30);
}
if(isset($_POST['boldText']))
{
echo "<b>";
}
echo "<font color='$textColor'>";
echo $userComments;
echo "</font>";
if (isset($_POST["boldText"]))
{
Â*Â*Â* echo "</b>";
}
?></body>
</html>

If I comment the setcookie() part, it works fine.. I looked up for some online help n most of them say I might have a whitespace near the line number mentioned in the warning message. But I don't find any.. Please help !



Did you know? You can CHAT without downloading messenger. Goto http://in.messenger.yahoo.com/webmessengerpromo.php/
Reply With Quote
  #2 (permalink)  
Old 07-15-2008
Dan Joseph
 
Posts: n/a
Default Re: [PHP] "Warning:Cannot modify header information -" Error

On Tue, Jul 15, 2008 at 11:51 AM, Tiji varghese <tijivarghese@yahoo.co.in>
wrote:

> Hi All !
> I am having some problem with the code below. Everytime I run it it gives
> me the following error:
> Warning: Cannot modify header information - headers already sent
> by (output started at
> C:\xampp\htdocs\practice.com\displayUserData.php:7 ) in C:\xampp\htdocs\
> practice.com\displayUserData.php on line 12
>
> The source code of the page is as follows:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title> new document </title>
> </head>
> <body>
> <?php $textColor = $_POST["TextColor"];
> $boldText = $_POST["boldText"];
> $userComments = stripslashes($_POST['userComments']);
> if(isset($_POST["saveInfo"]))
> {
> setcookie("userData",$userComments,time()+60*60*24 *30);
> }
> if(isset($_POST['boldText']))
> {
> echo "<b>";
> }
> echo "<font color='$textColor'>";
> echo $userComments;
> echo "</font>";
> if (isset($_POST["boldText"]))
> {
> echo "</b>";
> }
> ?></body>
> </html>
>
> If I comment the setcookie() part, it works fine.. I looked up for some
> online help n most of them say I might have a whitespace near the line
> number mentioned in the warning message. But I don't find any.. Please help
> !
>
>
>
> Did you know? You can CHAT without downloading messenger. Go to
> http://in.messenger.yahoo.com/webmessengerpromo.php/



The setcookie line needs to come before you output anything. Move your html
output at the top past it, and you should be good.

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."

Reply With Quote
  #3 (permalink)  
Old 07-15-2008
Daniel Brown
 
Posts: n/a
Default Re: [PHP] "Warning:Cannot modify header information -" Error

On Tue, Jul 15, 2008 at 11:51 AM, Tiji varghese
<tijivarghese@yahoo.co.in> wrote:
> Hi All !
> I am having some problem with the code below. Everytime I run it it gives me the following error:
> Warning: Cannot modify header information - headers already sent
> by (output started at
> C:\xampp\htdocs\practice.com\displayUserData.php:7 ) in C:\xampp\htdocs\practice.com\displayUserData.php on line 12


This message means that something was sent before line 12. In
your case, the HTML. All things that have to do with headers must be
before ANYTHING is sent to the browser. If you need to have the HTML
before a setcookie(), header(), or another header-based PHP action,
check into ob_start() and the other output-buffering functions PHP has
available.

--
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0