boonamera Posted July 16, 2006 Share Posted July 16, 2006 basically i'm trying to do something like this:index.php has: if($category == 0) { // GO to error.php }how would i go about making the page refresh to error.php?So if i understood correctly i can't used header because I have data above it.Then i can't use meta because that needs to be in the header.What's left? Quote Link to comment https://forums.phpfreaks.com/topic/14742-redirecting-to-different-page-after-having-sent-data/ Share on other sites More sharing options...
Branden Wagner Posted July 16, 2006 Share Posted July 16, 2006 you can use header(location: $url)or something like that i dont remember the exact syntax... regardless of the fact that there is code abovehowever you cant have output any datameaningthis will work[code]if($category == 0){ header(location: http://www.yoursite.com/error.php);}[/code][code]echo "blah";if($category == 0){ header(location: http://www.yoursite.com/error.php);}[/code]the second will fail becasue something has been output to the browser.make sense?correct syntax:[code]header("Location: http://www.yoursite.com/error.php");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14742-redirecting-to-different-page-after-having-sent-data/#findComment-58849 Share on other sites More sharing options...
akitchin Posted July 16, 2006 Share Posted July 16, 2006 you can echo a <meta> refresh anywhere on the page, and it will still be picked up. Quote Link to comment https://forums.phpfreaks.com/topic/14742-redirecting-to-different-page-after-having-sent-data/#findComment-58850 Share on other sites More sharing options...
quimbo Posted July 16, 2006 Share Posted July 16, 2006 if you've already sent headers you could try using the javascript location object:window.location.href = "http://yoursite.com/error.php" Quote Link to comment https://forums.phpfreaks.com/topic/14742-redirecting-to-different-page-after-having-sent-data/#findComment-58852 Share on other sites More sharing options...
PC Nerd Posted July 16, 2006 Share Posted July 16, 2006 you could also try to include the error.php, if the border styles and formating is the same. you could use something like if(condition){include("error.php";)}i would also rename the file .inc, so that it easy to tell wht it is used for.this is sometimes good for form validation, where you want to redisplay the form, the form would simply be in the inc file Quote Link to comment https://forums.phpfreaks.com/topic/14742-redirecting-to-different-page-after-having-sent-data/#findComment-58937 Share on other sites More sharing options...
boonamera Posted July 16, 2006 Author Share Posted July 16, 2006 thanks guysI got 2 versions working: with the meta and with the includeI couldn't use header as i had outputted preivously.I think the include method should do the trick but the only problem with it is that I would like the address to show http://domain.com/erroranyways of doing that?Otherwise ill stick with the meta,thx Quote Link to comment https://forums.phpfreaks.com/topic/14742-redirecting-to-different-page-after-having-sent-data/#findComment-59005 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.