mkosmosports Posted October 1, 2006 Share Posted October 1, 2006 Hello,Does anyone know how to invoke a redirect to another html page (error page) based on the condition that a user selects certain variables in the URL. I know an if statement would have to be used, and I would use "if $variable =>.." so greater than or equal to. But I cant think of a way to invoke the redirect.....Any suggestions?Thanks a lot,mkosmosports Link to comment https://forums.phpfreaks.com/topic/22666-redirects-based-on-url-variables/ Share on other sites More sharing options...
shivabharat Posted October 1, 2006 Share Posted October 1, 2006 Hi,You have to use the META tag for this[code]<meta http-equiv="refresh" content="2;url=http://mypage/index2.php">[/code] Link to comment https://forums.phpfreaks.com/topic/22666-redirects-based-on-url-variables/#findComment-101906 Share on other sites More sharing options...
HuggieBear Posted October 1, 2006 Share Posted October 1, 2006 Use the header() function...[code]<?phpif ($var == 1){ header("Location: index.php");}elseif ($var == 2){ header("Location: contact.php");}else { header("Location: error.php");}?>[/code]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/22666-redirects-based-on-url-variables/#findComment-101907 Share on other sites More sharing options...
wildteen88 Posted October 1, 2006 Share Posted October 1, 2006 If you want to redirect a user use header, For example say you had a login script and then you checked for the logout variabled in the url If you find it you'll redirect the user to the logout page:[code=php:0]if(isset($_GET['logout') && $_GET['logout'] == 'true'){ header("Location: logout.php");}[/code] Link to comment https://forums.phpfreaks.com/topic/22666-redirects-based-on-url-variables/#findComment-101910 Share on other sites More sharing options...
Daniel0 Posted October 1, 2006 Share Posted October 1, 2006 [quote author=shivabharat link=topic=110152.msg444786#msg444786 date=1159723004]Hi,You have to use the META tag for this[code]<meta http-equiv="refresh" content="2;url=http://mypage/index2.php">[/code][/quote]Not a good idea: http://www.w3.org/QA/Tips/reback Link to comment https://forums.phpfreaks.com/topic/22666-redirects-based-on-url-variables/#findComment-101911 Share on other sites More sharing options...
mkosmosports Posted October 1, 2006 Author Share Posted October 1, 2006 Thanks a lot for your help guys, I've tried the suggested methods and one of them works just the way I want it! Link to comment https://forums.phpfreaks.com/topic/22666-redirects-based-on-url-variables/#findComment-101930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.