Reputation: 45
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.
Upvotes: 0
Views: 690
Reputation: 1373
Here is your solution:
http://code.google.com/p/php-mobile-detect2/
Upvotes: 1
Reputation: 15251
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.
Upvotes: 0