PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.20.2
Last Build: October 16, 2017 12:40pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
file
graph
html
mail
math
misc
mobile
script
string
system
time
psIsMobileBrowser()
Check if browser is a mobile device


Description:

Used to check if browser is a mobile device
Note: compares to several strings, does not exit on first occurance, loops through all,
returns last matching. So order of tests is important.


Usage:

$str = psIsMobileBrowser(); // returns NULL or Device name (in lowercase)


Example:


if (psIsMobileBrowser() == "android")
{
// do android stuff here
}




Code:


function psIsMobileBrowser()
{
global $_SERVER;

$amDevices[] = "Mobile"; // we can catch alot with this
$amDevices[] = "IEMobile"; // we can catch alot with this too
$amDevices[] = "Android";
$amDevices[] = "DROIDX";
$amDevices[] = "Blackberry";
$amDevices[] = "iPad";
$amDevices[] = "iPhone";
$amDevices[] = "HTC";
$amDevices[] = "SAMSUNG";

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);

$flagMobile = "";
foreach ($amDevices as $device)
{
$device = strtolower($device);
if (strpos($ua,$device) !== false)
{
$flagMobile = $device;
}
}

return $flagMobile;
}




Changlelog:

05/26/2012 psIsMobileBrowser() returns device name instead of true

See Also

And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site