suess0r Posted January 11, 2007 Share Posted January 11, 2007 Hi, i'm trying to determine what browser the user is coming from (ie: safari, firefox, ie, netscape, opera) and redirect them to our website.com and if it's from another browser that's not recognized redirect them to our mobilesite.com.Right now i'm just trying to echo out what browser they have so i can redirect them after I know what browser they're on.<?function get_mybrowser(){ if(strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko')){ if(strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape')) return 'netscape'; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) return 'firefox'; else return 'mozilla'; }elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')){ if(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera')) return 'opera'; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')) return 'safari'; else return 'ie'; }else return 'other';}switch(get_mybrowser()){ default: echo "default"; break; case "ie": echo "ie"; break; case "mozilla": echo "mozilla"; break; case "firefox": echo "firefox"; break; case "safari"; echo "safari"; break; case "other"; echo "other"; break;}?>Problem is this... the mobile page says "Page cannot be displayed" which is odd because it does support the $_SERVER['HTTP_USER_AGENT']. I am wondering if I might have to take it out of a function, does anyone have any thoughts or touchups to the code?? Link to comment https://forums.phpfreaks.com/topic/33774-browser-redirect-mobile-vs-web/ Share on other sites More sharing options...
Guest rancid-tea Posted January 11, 2007 Share Posted January 11, 2007 [quote]switch(get_mybrowser()){ default: echo "default"; break;[/quote]Can you put the default before the cases? I've never seen it done this way.Do you have an example that we can look at online? Link to comment https://forums.phpfreaks.com/topic/33774-browser-redirect-mobile-vs-web/#findComment-158404 Share on other sites More sharing options...
emehrkay Posted January 11, 2007 Share Posted January 11, 2007 the switch case is unnecessary just echo the functionbut to address your question, you could doif($_SERVER['HTTP_USER_AGENT']){header("Location :website");}else{header("Location: mobil");} Link to comment https://forums.phpfreaks.com/topic/33774-browser-redirect-mobile-vs-web/#findComment-158417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.