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.

<? if(${"SubArea"}=="N")
{
?>
	<? setcookie("Copyright2009","do not agree",0,"","",0);
?>
	<? header("Location: "."copyrightNotAgree.php");?>
<? }?>
<? $strTemp=$_COOKIE["Copyright2009"];?>
<? echo $strTemp;?>
<? if($strTemp=="agree")
{
?>

	<? header("Location: "."index2.php");?>
<? }
  else
{
?>

	<? if(${"SubArea"}=="Y")
  {
?>

		<? setcookie("Copyright2009","agree",0,"","",0);
?><?php
//Calculate 30 days in the future
//seconds * minutes * hours * days + current time
$inOneMonth = 60 * 60 * 24 * 30 + time(); 
setcookie('lastVisit', date("G:i - m/d/y"), $inOneMonth); 
?>

<? $URL="http://www.mysite.com/index2.php";?>
	<?   }
    else
  {
?>

		<? header("Location: copyright.php");?>  (this is line 38 referred to in the error message)
	<?   } ?>
<? } ?>
Member Avatar for diafol

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

<? echo $strTemp;?>

will ensure your code goes "t*** up".

Thanks Buddie, methinks I had better bury my head in some books to get at least up to half speed on this coding lark!

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

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.

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..:-)

actually you dont need to erase all blank spaces either beginning nor ending, just add @ sign where your error is..:-)

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!!

Member Avatar for diafol

Thanks for resurrecting this dead post. Placing @ is not a replacement for proper coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.