class Mobile_Detect


Located at : UKNOWVA_ROOT/libraries/conv/mobiledetect.php

Constants

DETECTION_TYPE_MOBILE

Mobile detection type.

DETECTION_TYPE_EXTENDED

Extended detection type.

VER

A frequently used regular expression to extract version #s.

MOBILE_GRADE_A

Top-level device.

MOBILE_GRADE_B

Mid-level device.

MOBILE_GRADE_C

Low-level device.

VERSION

Stores the version number of the current release.

VERSION_TYPE_STRING

A type for the version() method indicating a string return value.

VERSION_TYPE_FLOAT

A type for the version() method indicating a float return value.

Methods

__construct(array $headers = null, string $userAgent = null)

Construct an instance of this class.

static string
getScriptVersion()

Get the current script version.

setHttpHeaders(array $httpHeaders = null)

Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.

array
getHttpHeaders()

Retrieves the HTTP headers.

string|null
getHttpHeader(string $header)

Retrieves a particular header. If it doesn't exist, no exception/error is caused.

setUserAgent(string $userAgent = null)

Set the User-Agent to be used.

string|null
getUserAgent()

Retrieve the User-Agent.

setDetectionType(string $type = null) deprecated

Set the detection type. Must be one of self::DETECTIONTYPEMOBILE or self::DETECTIONTYPEEXTENDED. Otherwise, nothing is set.

static array
getPhoneDevices()

Retrieve the list of known phone devices.

static array
getTabletDevices()

Retrieve the list of known tablet devices.

static array
getUserAgents()

Alias for getBrowsers() method.

static array
getBrowsers()

Retrieve the list of known browsers. Specifically, the user agents.

static array
getUtilities()

Retrieve the list of known utilities.

static array
getMobileDetectionRules() deprecated

Method gets the mobile detection rules. This method is used for the magic methods $detect->is*().

array
getMobileDetectionRulesExtended() deprecated

Method gets the mobile detection rules + utilities.

array
getRules() deprecated

Retrieve the current set of rules.

bool
checkHttpHeadersForMobile()

Check the HTTP headers for signs of mobile.

mixed
__call(string $name, array $arguments)

Magic overloading method.

bool
isMobile(null $userAgent = null, null $httpHeaders = null)

Check if the device is mobile.

bool
isTablet(string $userAgent = null, array $httpHeaders = null)

Check if the device is a tablet.

bool|int|null
is($key, string $userAgent = null, string $httpHeaders = null)

This method checks for a certain property in the userAgent.

static array
getOperatingSystems()

Retrieve the list of mobile operating systems.

bool
match($regex, string $userAgent = null)

Some detection rules are relative (not standard), because of the diversity of devices, vendors and their conventions in representing the User-Agent or the HTTP headers.

static array
getProperties()

Get the properties array.

float
prepareVersionNo(string $ver)

Prepare the version number.

string|float
version(string $propertyName, string $type = self::VERSION_TYPE_STRING)

Check the version of the given property in the User-Agent.

string
mobileGrade()

Retrieve the mobile grading, using self::MOBILEGRADE* constants.

Details

at line 410
__construct(array $headers = null, string $userAgent = null)

Construct an instance of this class.

Parameters

array $headers Specify the headers as injection. Should be PHP SERVER flavored. If left empty, will use the global _SERVER['HTTP*'] vars instead.
string $userAgent Inject the User-Agent header. If null, will use HTTPUSERAGENT from the $headers array instead.

at line 426
static string getScriptVersion()

Get the current script version.

This is useful for the demo.php file, so people can check on what version they are testing for mobile devices.

Return Value

string The version number in semantic version format.

at line 437
setHttpHeaders(array $httpHeaders = null)

Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.

Parameters

array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract the headers. The default null is left for backwards compatibilty.

at line 461
array getHttpHeaders()

Retrieves the HTTP headers.

Return Value

array

at line 476
string|null getHttpHeader(string $header)

Retrieves a particular header. If it doesn't exist, no exception/error is caused.

Simply null is returned.

Parameters

string $header The name of the header to retrieve. Can be HTTP compliant such as "User-Agent" or "X-Device-User-Agent" or can be php-esque with the all-caps, HTTP_ prefixed, underscore seperated awesomeness.

Return Value

string|null The value of the header.

at line 500
setUserAgent(string $userAgent = null)

Set the User-Agent to be used.

Parameters

string $userAgent The user agent string to set.

at line 524
string|null getUserAgent()

Retrieve the User-Agent.

Return Value

string|null The user agent if it's set.

at line 538
setDetectionType(string $type = null) deprecated

deprecated since version 2.6.9

Set the detection type. Must be one of self::DETECTIONTYPEMOBILE or self::DETECTIONTYPEEXTENDED. Otherwise, nothing is set.

Parameters

string $type The type. Must be a self::DETECTIONTYPE* constant. The default parameter is null which will default to self::DETECTIONTYPEMOBILE.

at line 556
static array getPhoneDevices()

Retrieve the list of known phone devices.

Return Value

array List of phone devices.

at line 566
static array getTabletDevices()

Retrieve the list of known tablet devices.

Return Value

array List of tablet devices.

at line 576
static array getUserAgents()

Alias for getBrowsers() method.

Return Value

array List of user agents.

at line 586
static array getBrowsers()

Retrieve the list of known browsers. Specifically, the user agents.

Return Value

array List of browsers / user agents.

at line 596
static array getUtilities()

Retrieve the list of known utilities.

Return Value

array List of utilities.

at line 608
static array getMobileDetectionRules() deprecated

deprecated since version 2.6.9

Method gets the mobile detection rules. This method is used for the magic methods $detect->is*().

Return Value

array All the rules (but not extended).

at line 635
array getMobileDetectionRulesExtended() deprecated

deprecated since version 2.6.9

Method gets the mobile detection rules + utilities.

The reason this is separate is because utilities rules don't necessary imply mobile. This method is used inside the new $detect->is('stuff') method.

Return Value

array All the rules + extended.

at line 660
array getRules() deprecated

deprecated since version 2.6.9

Retrieve the current set of rules.

Return Value

array

at line 676
bool checkHttpHeadersForMobile()

Check the HTTP headers for signs of mobile.

This is the fastest mobile check possible; it's used inside isMobile() method.

Return Value

bool

at line 713
mixed __call(string $name, array $arguments)

Magic overloading method.

Parameters

string $name
array $arguments

Return Value

mixed

Exceptions

BadMethodCallException when the method doesn't exist and doesn't start with 'is'

at line 783
bool isMobile(null $userAgent = null, null $httpHeaders = null)

Check if the device is mobile.

Returns true if any type of mobile device detected, including special ones

Parameters

null $userAgent deprecated
null $httpHeaders deprecated

Return Value

bool

at line 811
bool isTablet(string $userAgent = null, array $httpHeaders = null)

Check if the device is a tablet.

Return true if any type of tablet device is detected.

Parameters

string $userAgent deprecated
array $httpHeaders deprecated

Return Value

bool

at line 834
bool|int|null is($key, string $userAgent = null, string $httpHeaders = null)

This method checks for a certain property in the userAgent.

Parameters

$key
string $userAgent deprecated
string $httpHeaders deprecated

Return Value

bool|int|null

at line 855
static array getOperatingSystems()

Retrieve the list of mobile operating systems.

Return Value

array The list of mobile operating systems.

at line 875
bool match($regex, string $userAgent = null)

Some detection rules are relative (not standard), because of the diversity of devices, vendors and their conventions in representing the User-Agent or the HTTP headers.

This method will be used to check custom regexes against the User-Agent string.

Parameters

$regex
string $userAgent

Return Value

bool

at line 888
static array getProperties()

Get the properties array.

Return Value

array

at line 902
float prepareVersionNo(string $ver)

Prepare the version number.

Parameters

string $ver The string version, like "2.6.21.2152";

Return Value

float

at line 927
string|float version(string $propertyName, string $type = self::VERSION_TYPE_STRING)

Check the version of the given property in the User-Agent.

Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)

Parameters

string $propertyName The name of the property. See self::getProperties() array keys for all possible properties.
string $type Either self::VERSIONTYPESTRING to get a string value or self::VERSIONTYPEFLOAT indicating a float value. This parameter is optional and defaults to self::VERSIONTYPESTRING. Passing an invalid parameter will default to the this type as well.

Return Value

string|float The version of the property we are trying to extract.

at line 975
string mobileGrade()

Retrieve the mobile grading, using self::MOBILEGRADE* constants.

Return Value

string One of the self::MOBILEGRADE* constants.