Cannot modify header information......

Reply

Join Date: Feb 2009
Posts: 2
Reputation: kimphot is an unknown quantity at this point 
Solved Threads: 0
kimphot kimphot is offline Offline
Newbie Poster

Cannot modify header information......

 
0
  #1
Feb 1st, 2009
Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/redirect_index.php:20) in /home/mysite/public_html/redirect_index.php on line 38

I've converting as asp site to php. I'm a partial numpty in asp and complete numpty in php

I keep being told this is a white space problem..... I can't see it!

The code below is a redirect: from one page to another where a Yes or No is clicked and then redirected accordingly.

The asp code was "converted" to php using a conversion prog, so anything could have happened! Maybe the sequence of events is incorrect?

Any advice greatly appreciated.

  1. <? if(${"SubArea"}=="N")
  2. {
  3. ?>
  4. <? setcookie("Copyright2009","do not agree",0,"","",0);
  5. ?>
  6. <? header("Location: "."copyrightNotAgree.php");?>
  7. <? }?>
  8. <? $strTemp=$_COOKIE["Copyright2009"];?>
  9. <? echo $strTemp;?>
  10. <? if($strTemp=="agree")
  11. {
  12. ?>
  13.  
  14. <? header("Location: "."index2.php");?>
  15. <? }
  16. else
  17. {
  18. ?>
  19.  
  20. <? if(${"SubArea"}=="Y")
  21. {
  22. ?>
  23.  
  24. <? setcookie("Copyright2009","agree",0,"","",0);
  25. ?><?php
  26. //Calculate 30 days in the future
  27. //seconds * minutes * hours * days + current time
  28. $inOneMonth = 60 * 60 * 24 * 30 + time();
  29. setcookie('lastVisit', date("G:i - m/d/y"), $inOneMonth);
  30. ?>
  31.  
  32. <? $URL="http://www.mysite.com/index2.php";?>
  33. <? }
  34. else
  35. {
  36. ?>
  37.  
  38. <? header("Location: copyright.php");?> (this is line 38 referred to in the error message)
  39. <? } ?>
  40. <? } ?>
Last edited by peter_budo; Feb 3rd, 2009 at 1:46 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,066
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 136
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: Cannot modify header information......

 
0
  #2
Feb 1st, 2009
You can't have anything echoed to the screen (including whitespace) before the header() function.

  1. <? echo $strTemp;?>

will ensure your code goes "t*** up".
Last edited by ardav; Feb 1st, 2009 at 8:55 am.
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 2
Reputation: kimphot is an unknown quantity at this point 
Solved Threads: 0
kimphot kimphot is offline Offline
Newbie Poster

Re: Cannot modify header information......

 
0
  #3
Feb 2nd, 2009
Thanks Buddie, methinks I had better bury my head in some books to get at least up to half speed on this coding lark!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 13
Reputation: mr.khurrams is an unknown quantity at this point 
Solved Threads: 2
mr.khurrams mr.khurrams is offline Offline
Newbie Poster

Re: Cannot modify header information......

 
0
  #4
Feb 2nd, 2009
if you still want to make is as error free please use ob_start() function at the start of this page. ob_start() function will handle this error
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 87
Reputation: TopDogger is an unknown quantity at this point 
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: Cannot modify header information......

 
0
  #5
Feb 3rd, 2009
You do not need all of those PHP start and end tags.

You only need one at the beginning of the PHP code and one at the end. Any blank line in between a close and start tag is being sent to the browser. Eliminate all of the unecessary PHP start and end tags and your problem will go away.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC