0

I have to make 2versions of my site, i.e., 1 version for Mobile phone and 1 version for our PC. So I have a script as follows:-

<?php 
if ( stristr($ua, "Windows CE") or stristr($ua, "AvantGo") or 
     stristr($ua,"Mazingo") or stristr($ua, "Mobile") or stristr($ua, "T68") or
     stristr($ua,"Syncalot") or stristr($ua, "Blazer") or 
     stristr($ua,"Mozilla") or stristr($ua,"Firefox") )
{
     $DEVICE_TYPE="MOBILE";
}
if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE") 
{
    $location='mobile/entry.html';
    header ('Location: '.$location);
    exit;
}
else
{ 
    $location='entry.html';
    header ('Location: '.$location);
    exit;
}
?>

This script works well with my PC, but if I try to access my site from mobile, I cannot redirect to the same page as I want.

Can anyone help me resolve this issue?

Thanks in Advance.

Steve Weet
  • 28,126
  • 11
  • 70
  • 86
Priyanka
  • 45
  • 1
  • 5
  • possible duplicate of [How to Detect Mobile Browser Capability](http://stackoverflow.com/questions/3428234/how-to-detect-mobile-browser-capability) – Pekka Aug 12 '10 at 10:40
  • @Pekka most links in Sarfraz post unfortunately don't work – Sotiris Aug 12 '10 at 10:55

3 Answers3

1

Here is your solution:

http://code.google.com/p/php-mobile-detect2/

Sergej Brazdeikis
  • 1,323
  • 10
  • 11
0

You can read Lightweight Device-Detection in PHP

Sotiris
  • 38,986
  • 11
  • 53
  • 85
0

The best option is not to try and redirect based on user-agent sniffing, but to put your mobile content onto a specific url, and make those options available. User-agent sniffing is ok up to a point, but you cannot rely on it 100%. Related to this, PPK's post on javascript detection is good reading.

That said, if you are dead set on doing user-agent redirection, you will need to have some way to be able to update your list of devices, and user-agent strings - something like codeigniter's user agent class will be more useful over the long run.

danp
  • 14,876
  • 6
  • 42
  • 48