Jump to content

browser redirect mobile vs web!?!?


suess0r

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.