shortysbest Posted April 1, 2010 Share Posted April 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/197295-php-redirect-to-error-page-has-error-on-server-but-not-localhost/ Share on other sites More sharing options...
jcbones Posted April 1, 2010 Share Posted April 1, 2010 Make sure there is no spaces before <?php Quote Link to comment https://forums.phpfreaks.com/topic/197295-php-redirect-to-error-page-has-error-on-server-but-not-localhost/#findComment-1035539 Share on other sites More sharing options...
shortysbest Posted April 1, 2010 Author Share Posted April 1, 2010 Make sure there is no spaces before <?php There isn't and the rest of the code works fine, (changing the pages and all) Quote Link to comment https://forums.phpfreaks.com/topic/197295-php-redirect-to-error-page-has-error-on-server-but-not-localhost/#findComment-1035540 Share on other sites More sharing options...
GetPutDelete Posted April 1, 2010 Share Posted April 1, 2010 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!). Quote Link to comment https://forums.phpfreaks.com/topic/197295-php-redirect-to-error-page-has-error-on-server-but-not-localhost/#findComment-1035542 Share on other sites More sharing options...
shortysbest Posted April 1, 2010 Author Share Posted April 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/197295-php-redirect-to-error-page-has-error-on-server-but-not-localhost/#findComment-1035544 Share on other sites More sharing options...
GetPutDelete Posted April 1, 2010 Share Posted April 1, 2010 No problem, don't forget to set the thread to solved. Quote Link to comment https://forums.phpfreaks.com/topic/197295-php-redirect-to-error-page-has-error-on-server-but-not-localhost/#findComment-1035545 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.