943,866 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1018
  • PHP RSS
Feb 1st, 2009
0

Cannot modify header information......

Expand Post »
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.

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kimphot is offline Offline
2 posts
since Feb 2009
Feb 1st, 2009
0

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

You can't have anything echoed to the screen (including whitespace) before the header() function.

PHP Syntax (Toggle Plain Text)
  1. <? echo $strTemp;?>

will ensure your code goes "t*** up".
Last edited by ardav; Feb 1st, 2009 at 8:55 am.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 948
Sarcastic Poster
ardav is offline Offline
6,694 posts
since Oct 2006
Feb 2nd, 2009
0

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

Thanks Buddie, methinks I had better bury my head in some books to get at least up to half speed on this coding lark!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kimphot is offline Offline
2 posts
since Feb 2009
Feb 2nd, 2009
0

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

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
Reputation Points: 10
Solved Threads: 2
Newbie Poster
mr.khurrams is offline Offline
13 posts
since Oct 2008
Feb 3rd, 2009
0

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

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.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005
Mar 6th, 2010
0
Re: Cannot modify header information......
hi
my name is paul who have the username of (http://)wbtech.zxq.net this is the address my online banking, i'm the one who coded this online bank, i've got the error "Warning: Cannot modify header information - headers already sent by" but one that i did to remove this tricky error is adding a "@" sign before the word header>> @header just like this, then boom!, its gone, also the session_start() >>"Warning: Cannot modify header information - headers already sent by" i also just add a "@" in session_start >>>@session_start(); just like this..then all done..:-)
Reputation Points: 10
Solved Threads: 1
Newbie Poster
wbtech.zxq.net is offline Offline
4 posts
since Mar 2010
Mar 6th, 2010
0
Re: Cannot modify header information......
actually you dont need to erase all blank spaces either beginning nor ending, just add @ sign where your error is..:-)
Reputation Points: 10
Solved Threads: 1
Newbie Poster
wbtech.zxq.net is offline Offline
4 posts
since Mar 2010
Mar 6th, 2010
-1
Re: Cannot modify header information......
Cannot send session cache limiter>> is should say in the session_start(); just add a "@" sign..that's all folks!, hi add me in my facebook my email is paul_cbrr@yahoo.com see yah!!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
wbtech.zxq.net is offline Offline
4 posts
since Mar 2010
Mar 6th, 2010
0
Re: Cannot modify header information......
Thanks for resurrecting this dead post. Placing @ is not a replacement for proper coding.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 948
Sarcastic Poster
ardav is offline Offline
6,694 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to link news items by ID
Next Thread in PHP Forum Timeline: Back button in MultiForm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC