Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.