Jump to content

Recommended Posts

Hi,

I have a Web Site and a Mobile Site, i'm trying to determine the browser and redirecting the user depending on which they choose from. I have the script working for the most part, but there are more instances that don't fall under the categories (such as i'm using IE on my mobile device so it's redirecting me to the web site.) Does anyone konw any way around this, or have a list of $_SERVER['HTTP_USER_AGENT']'s for a mobile device I can add or any suggestions for me that could help better my script to be more dependable (not only checking for PC browsers, and push everything that doesn't fall under those categories, but are actual mobile browsers?)

Code Below...

[quote]<?php
global $userBrowser;

$wmllink = "http://www.mclb411.com/mpg1.php";

$htmllink = "http://www.clb411.com/pg1.php";


$userBrowser = $_SERVER['HTTP_USER_AGENT'];

//echo $userBrowser;

//Check for Mozilla
if(stristr($userBrowser, 'Mozilla'))
{
  $ub="PC";
}
//Check for Mozilla
elseif(stristr($userBrowser, 'gecko'))
{
  $ub="PC";
}
//Check for opera
elseif(stristr($userBrowser, 'opera'))
{
  $ub="PC";
}
//Check for omniweb
elseif(stristr($userBrowser, 'omniweb'))
{
  $ub="PC";
}
//Check for msie
elseif(stristr($userBrowser, 'msie'))
{
  $ub="PC";
}
//Check for konqueror
elseif(stristr($userBrowser, 'konqueror'))
{
  $ub="PC";
}
//Check for safari
elseif(stristr($userBrowser, 'safari'))
{
  $ub="PC";
}
//Check for netpositive
elseif(stristr($userBrowser, 'netpositive'))
{
  $ub="PC";
}
//Check for lynx
elseif(stristr($userBrowser, 'lynx'))
{
  $ub="PC";
}
//Check for elinks
elseif(stristr($userBrowser, 'elinks'))
{
  $ub="PC";
}
//Check for Mozilla
elseif(stristr($userBrowser, 'Mozilla'))
{
  $ub="PC";
}
//Check for links
elseif(stristr($userBrowser, 'links'))
{
  $ub="PC";
}
//Check for w3m
elseif(stristr($userBrowser, 'w3m'))
{
  $ub="PC";
}
//Check for webtv
elseif(stristr($userBrowser, 'webtv'))
{
  $ub="PC";
}
//Check for amaya
elseif(stristr($userBrowser, 'amaya'))
{
  $ub="PC";
}
//Check for dillo
elseif(stristr($userBrowser, 'dillo'))
{
  $ub="PC";
}
//Check for ibrowse
elseif(stristr($userBrowser, 'ibrowse'))
{
  $ub="PC";
}
//Check for icab
elseif(stristr($userBrowser, 'icab'))
{
  $ub="PC";
}
//Check for crazy browser
elseif(stristr($userBrowser, 'crazy browser'))
{
  $ub="PC";
}
//Check for IE
elseif(stristr($userBrowser, 'internet explorer'))
{
  $ub="PC";
}
//If it's not any of the above browsers
//Then it gotta be a WML or very unpopular browser
else
{
  $ub="WML";
  }
//Code for redirecting based upon the results
if($ub == "PC") {
    header("Location: ".$htmllink);
    exit;
    }
    else
    {
    header("Location: ".$wmllink);
    exit;
    }

?>[/quote]
Link to comment
https://forums.phpfreaks.com/topic/36296-mobile-vs-web-browser-redirection/
Share on other sites

from what i remember testing this a while back, PalmPC's/Mobiles/PDA's etc create extra variables (other than the HTTP_USER_AGENT) in the $_SERVER array. if you do a print_r dump of the $_SERVER array and run the script on the mobile device, you should be able to pick out what they are. I'll post them here if i find the script I was playing with...
Thanks marky, ya i tried doing an echo on the actual $_SERVER['HTTP_USER_AGENT']; and it says The Request Page cannot be Displayed.... but if i take the echo off it directs to a PC page (because it is some mobile version of IE taht I guess is getting passed as msie) if you come accross any of those differences in the variables in the $SERVER array that would help a lot, thanks!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.