hasanatkazmi Posted August 10, 2007 Share Posted August 10, 2007 i have a code like if (...) { forward to xxx.php } now this is conditional so i cant use javascript and i also dont want to use that, how to do this in PHP, by forwading i mean opening a new page Quote Link to comment https://forums.phpfreaks.com/topic/64189-how-to-forward-a-page-using-php/ Share on other sites More sharing options...
trq Posted August 10, 2007 Share Posted August 10, 2007 header("Location: http://site.com/otherpage.php"); Quote Link to comment https://forums.phpfreaks.com/topic/64189-how-to-forward-a-page-using-php/#findComment-319990 Share on other sites More sharing options...
hasanatkazmi Posted August 10, 2007 Author Share Posted August 10, 2007 header should be declared before eching any thing, it gave me error "Warning: Cannot modify header information - headers already sent by" I need to forward my page somewhere in the middle, how to?? Quote Link to comment https://forums.phpfreaks.com/topic/64189-how-to-forward-a-page-using-php/#findComment-320001 Share on other sites More sharing options...
trq Posted August 10, 2007 Share Posted August 10, 2007 Why would you need to echo any data if all your going to do is redirect? It makes no sense. You need to re-arrange your logic. Quote Link to comment https://forums.phpfreaks.com/topic/64189-how-to-forward-a-page-using-php/#findComment-320053 Share on other sites More sharing options...
schme16 Posted August 10, 2007 Share Posted August 10, 2007 place this at the top of your pages using header redirects: ob_start(); it clears header cache... Quote Link to comment https://forums.phpfreaks.com/topic/64189-how-to-forward-a-page-using-php/#findComment-320069 Share on other sites More sharing options...
climbjm Posted August 10, 2007 Share Posted August 10, 2007 Agreed with thorpe... However if you wanted like a little 'splash' page that says something like, you will be redirected in five seconds... I would recommend using JavaScript. However, if they have JavaScript disabled or a JavaScript non-supported browser... they wont be redirected. this is why you usually provide a link stating "if you have not been re-directed in 5 seconds, please click here". It is usually easier to use a client side script to re-direct with a 5 second splash page opposed to having a server side redirect you. If you want this to be instantaneous... use the method above. header("Location: http://site.com/otherpage.php"); For a JavaScript redirect tutorial, check here: http://www.tizag.com/javascriptT/javascriptredirect.php Quote Link to comment https://forums.phpfreaks.com/topic/64189-how-to-forward-a-page-using-php/#findComment-320133 Share on other sites More sharing options...
Sesquipedalian Posted August 10, 2007 Share Posted August 10, 2007 Not quite sure how logical this may be, but if you want to go to another page maybe you could just just use include? Like.. if (..) { include('page.php'); } But if it turns out that you have something that is already written out that you don't want there, you could always try to just set the text that is displayed before the redirect, and destroy it as you redirect. Something like: $text = 'Hello World'; echo $text; if (..) { unset($text); include('page.php'); } Those are my thoughts.. This would only work if it is inside of a function. Quote Link to comment https://forums.phpfreaks.com/topic/64189-how-to-forward-a-page-using-php/#findComment-320138 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.