473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Cannot modify header information - headers already sent by (output ...

274 100+
I get following error on page :
Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\desiorb\411.php:9) in C:\xampp\htdocs\desiorb\411.php on line 21
when I set a cookie on first page. Please help me fix it.
here is code fot both pages
411.php
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="411process.php" method="post">
  4.     Email adddress: <input type="text" name="email" />
  5.     Cell #: <input type="text" name="cell" />
  6.     <input type="Submit" value = "Subscribe"/>
  7.     <input type="checkbox" name="option_SportsPicks" value="SportsPicks"  checked> SportsPicks
  8.     <input type="checkbox" name="option_StockPicks" value="StockPicks" checked > Stock Picks
  9.     <input type="checkbox" name="option_Wedding" value="Wedding" checked> Wedding
  10.     <input type="checkbox" name="option_Tech" value="Tech" checked> Tech. 
  11.     <input type="checkbox" name="option_Fashion" value="Fashion" checked> Fashion 
  12.     <input type="checkbox" name="option_Events" value="Events" checked> Events 
  13.     <input type="checkbox" name="option_Entertainment" value="Entertainment" checked> Entertainment
  14.     <input type="checkbox" name="option_RealEstate" value="RealEstate" checked> Real Estate 
  15.     <input type="checkbox" name="option_Auto" value="Auto" checked> Auto 
  16.     <input type="checkbox" name="option_Employment" value="Employment" checked> Employment 
  17.     <input type="checkbox" name="option_Cuisine" value="Cuisine" checked> Cuisine <br><br><br>
  18. </form>
  19. Sports
  20. <a href="411Directory.php" type="submit"><img src="buttons/sportspicks.png" alt="Sports Picks" name="sportspicks" id="sportspicks"  onclick="411Process.php" border="0" ></a>
  21. <?php setcookie("id","sportspicks",time()+3600);?>
  22. Auto
  23. <a href="411Directory.php"><img src="buttons/auto.png" alt="auto" name="auto" id="Auto" border="0" ></a><br><br>
  24. Stock Picks
  25. <a href="411Directory.php"><img src="buttons/stockpicks.png" alt="stockpicks" name="stockpicks" id="stockpicks" border="0"></a>
  26. Events
  27. <a href="411Directory.php"><img src="buttons/events.png" alt="events" name="events" id="events" border="0"></a><br><br>
  28. Entertainment
  29. <a href="411Directory.php"><img src="buttons/entertainment.png" alt="entertainment" name="entertainment" id="entertainment" border="0"></a>
  30. Wedding
  31. <a href="411Directory.php"><img src="buttons/wedding.png" alt="wedding" name="wedding" id="wedding" border="0" ></a><br><br>
  32. Fashion
  33. <a href="411Directory.php"><img src="buttons/fashion.png" alt="fashion" name="fashion" id="fashion" border="0" ></a>
  34. Cuisine
  35. <a href="411Directory.php"><img src="buttons/cuisine.png" alt="cuisine" name="cuisine" id="cuisine" border="0"></a><br><br>
  36. Real Estate
  37. <a href="411Directory.php"><img src="buttons/realestate.png" alt="realestate" name="realestate" id="realestate" border="0"></a>
  38. Tech
  39. <a href="411Directory.php"><img src="buttons/tech.png" alt="tech" name="tech" id="tech" border="0"></a><br><br>
  40. Employment
  41. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="lastpage.htm"><img src="buttons/employment.png" alt="employment" name="employment" id="employment" border="0"></a>
  42. </body>
  43. </html>
411Directory.php
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <?php
  4. $id=$_COOKIE["id"];
  5. // Print a cookie
  6. echo $_COOKIE["id"];
  7. // A way to view all cookies
  8. print_r($_COOKIE);
  9. ?>
  10. </body>
  11. </html>
this is my second day that I am playing with PHP but ths error screwedup my mind.
Please tell what I should do?
thanks in advance.
Jul 16 '08 #1
2 2219
Atli
5,058 Expert 4TB
When you set a cookie PHP must add headers to the HTTP Response.
The problem is that when you start printing content, even it that content is just a single white space before the <?php tag, the headers are sent, at which time PHP is unable to add new headers.

So, that means you must set any headers, including cookies, before you send anything else.

If you absolutely must send some content before setting the cookie, you can use Output buffering to delay the output until you chose to send it.

Somewhat like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ob_start(); // Start buffering output
  3.  
  4. echo "This stuff just had to be sent before the cookie!";
  5. setcookie(...);
  6.  
  7. ob_end_flush(); // Release the output to the response
  8. ?>
  9.  
Jul 16 '08 #2
creative1
274 100+
Thanks a lot . I am not sending data using cookies any more but it dis help understanding what the reason and solution of the problem is. I went through many solution but I found it useful.
Thanks again
Jul 16 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Phyzlo | last post by:
Hello, I've recently started learning PHP and have a question. I tried running below script which can be found at http://se2.php.net/manual/sv/function.setcookie.php but I keep getting this...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
5
by: Chris Robb | last post by:
I'm having some really odd behavior with a PHP script. I have it populating an HTML select form with a for loop. When I try the years 2006 to 1900. I get the following error: PHP Warning: ...
5
by: J Huntley Palmer | last post by:
I am getting this error: Cannot modify header information - headers already sent by when I issue a header ("Location: http://www.foobar.com"); How can I redirect the user to such a site...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
8
by: mcserret | last post by:
I know this is a recurring problem that has been addressed here before, but even after reading all that has gone before, I am still stumped. I have a form that is designed to send data to a PHP...
2
by: smartic | last post by:
I'm having problem with header redirection that is my code: <?php header("location:Redirecting.php"); exit; ?> //Then the HTML It give me an error
3
by: TechnoAtif | last post by:
Hi All. I have got problem with the header. If i run my php script in the local host it runs perfectly but if i do the same on net after loading it via ftp. it gives following error: The code...
2
by: pks83 | last post by:
Hello I am also facing this problem when i amtrying to send additional header information. Warning: Cannot modify header information - headers already sent by (output started at header.php:96)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.