PHP Salt


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

Version: 2.33.2
Last Build: December 29, 2023 20:28pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
db
file
graph
html
mail
math
misc
mobile
script
string
system
time
web
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 = array();
$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:

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