Friday, April 6, 2012

Detecting Mobile and Pc Browser Using PHP

Detecting Mobile and Pc Browser Using PHP

Here below is the simple way to detect the mobile or pc browser using some PHP codes. Using this code we can redirect users to their right place depending on their browser type.
However this code will only detect the Windows and Linux users. So it will return a mobile browser if the visitors browser is not either windows or linux.

PHP Code:
<?php
$UA
=strtolower($_SERVER['HTTP_USER_AGENT']);
if(
stristr($UA"windows"))
{
echo 
"i m a pc windows user";
}
else if(
stristr($UA"linux"))
{
print 
"i m pc linux user";
}
else
{
print 
"i m mobile or handheld user";
}

?>

No comments:

Post a Comment