Flying Sagittarius Posted June 13, 2008 Share Posted June 13, 2008 I'm using PHP scripting, not ASP. Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/ Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 this has to be used before any whitespace before or after <?php, ?> or before any html is written out header('Location:http://www.anotherlocation.com'); Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564506 Share on other sites More sharing options...
Flying Sagittarius Posted June 13, 2008 Author Share Posted June 13, 2008 Can you give me an example of how to use it? <html> <head> </head> <body> <?php header("Location:www.example.com"); ?> </body> </html> Like that? Can I add some PHP script before the header function? Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564508 Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 no html tags before the header. all the php you want, but no echos; -----------------------top of the page------------------- <?php //no whitespace before this tag your code with no echos; header('Location:http://www.anotherlocation.com'); ?> no whitespace between code and this tag --------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564518 Share on other sites More sharing options...
Flying Sagittarius Posted June 13, 2008 Author Share Posted June 13, 2008 Ok, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564521 Share on other sites More sharing options...
xtopolis Posted June 13, 2008 Share Posted June 13, 2008 <?php echo '<meta http-equiv="refresh" content="0;url=http://www.someurl.com/" />'; exit(); ?> This can be outputed at anytime and will attempt to redirect the user to someurl. It's best to put exit(); after calling this so that a non regular browser (ie: PERL masquerading as a browser) will not get any additional info. Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564552 Share on other sites More sharing options...
haku Posted June 13, 2008 Share Posted June 13, 2008 Search engines really dislike meta tag redirects. Much better to use a php redirect in the header. Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564862 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 13, 2008 Share Posted June 13, 2008 Personally, I use a javascript refresh to another page. Not the easiest solution, and it only adds another spice to the soup, but it works like a charm! FlyingIsFun1217 Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564866 Share on other sites More sharing options...
haku Posted June 13, 2008 Share Posted June 13, 2008 Javascript redirects are another one that the search engines hate. .htaccess 301 redirects are also a good way to go. Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-564871 Share on other sites More sharing options...
Flying Sagittarius Posted June 13, 2008 Author Share Posted June 13, 2008 PHP worked the best for me. I've learned that meta- and javascript redirects are discouraged by W3. .htaccess only works on Linux. Even so, I still can't figure out output buffering. If there's a way to redirect without using headers, I'd appreciate it being posted here. Quote Link to comment https://forums.phpfreaks.com/topic/110005-how-to-redirect-users/#findComment-565166 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.