Jump to content

PHP redirect to error page has error on server but not localhost


shortysbest

Recommended Posts

I have some php code that says if the page specified in url isnt found it will auto-redirect to the error page. it works perfectly on my localhost, however when i put it on my hosting server it comes back with an error.

 

The error:

 

Warning: Cannot modify header information - headers already sent by (output started at /www/zzl.org/d/c/t/dctestserver/htdocs/sw.php:4) in /www/zzl.org/d/c/t/dctestserver/htdocs/sw.php  on line 34

 

 

The Code:

 

<?php
$page = $_GET['page'];
if ($page)
{
	$path = "inc/".$page.".php";	
	if(file_exists($path))

	{

	include($path);

	}	
	else
	{
		$URL="sw.php?page=error"; header ("Location: $URL");    
	}
}
else
{
	$URL="sw.php?page=home"; header ("Location: $URL");

}
?>

 

Line 34 would be this line of code:

$URL="sw.php?page=error"; header ("Location: $URL");

 

any idea why this is? again it works pefectly fine on my localhost.

Headers are designed to work before there is any output on the site. The error you are getting is typical of there being HTML before the header function. You should check that PHP isn't echo'ing anything prior to this (that includes PHP error messages too!).

Headers are designed to work before there is any output on the site. The error you are getting is typical of there being HTML before the header function. You should check that PHP isn't echo'ing anything prior to this (that includes PHP error messages too!).

 

 

Ahhh, That was the problem. Thanks.. Knew it had to be something simple such as the placing of the code. Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.