Constants

DETECTION_TYPE_MOBILE

DETECTION_TYPE_MOBILE

Mobile detection type.

DETECTION_TYPE_EXTENDED

DETECTION_TYPE_EXTENDED

Extended detection type.

VER

VER

A frequently used regular expression to extract version #s.

MOBILE_GRADE_A

MOBILE_GRADE_A

Top-level device.

MOBILE_GRADE_B

MOBILE_GRADE_B

Mid-level device.

MOBILE_GRADE_C

MOBILE_GRADE_C

Low-level device.

VERSION

VERSION

Stores the version number of the current release.

VERSION_TYPE_STRING

VERSION_TYPE_STRING

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

VERSION_TYPE_FLOAT

VERSION_TYPE_FLOAT

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

Properties

$userAgent

$userAgent : string

The User-Agent HTTP header is stored in here.

Type

string

$httpHeaders

$httpHeaders : array

HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE.

Type

array

$matchingRegex

$matchingRegex : string

The matching Regex.

This is good for debug.

Type

string

$matchesArray

$matchesArray : string

The matches extracted from the regex expression.

This is good for debug.

Type

string

$detectionType

$detectionType : string

The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED.

Type

string

$mobileHeaders

$mobileHeaders : array

HTTP headers that trigger the 'isMobile' detection to be true.

Type

array

$phoneDevices

$phoneDevices : array

List of mobile devices (phones).

Type

array

$tabletDevices

$tabletDevices : array

List of tablet devices.

Type

array

$operatingSystems

$operatingSystems : array

List of mobile Operating Systems.

Type

array

$browsers

$browsers : array

List of mobile User Agents.

Type

array

$utilities

$utilities : array

Utilities.

Type

array

$uaHttpHeaders

$uaHttpHeaders : array

All possible HTTP headers that represent the User-Agent string.

Type

array

$properties

$properties : array

The individual segments that could exist in a User-Agent string. VER refers to the regular expression defined in the constant self::VER.

Type

array

Methods

__construct()

__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 HTTP_USER_AGENT from the $headers array instead.

getScriptVersion()

getScriptVersion() : string

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.

Returns

string —

The version number in semantic version format.

setHttpHeaders()

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.

getHttpHeaders()

getHttpHeaders() : array

Retrieves the HTTP headers.

Returns

array

getHttpHeader()

getHttpHeader(string  $header) : string|null

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.

Returns

string|null —

The value of the header.

getMobileHeaders()

getMobileHeaders() 

getUaHttpHeaders()

getUaHttpHeaders() : array

Get all possible HTTP headers that can contain the User-Agent string.

Returns

array —

List of HTTP headers.

setUserAgent()

setUserAgent(string  $userAgent = null) : string|null

Set the User-Agent to be used.

Parameters

string $userAgent

The user agent string to set.

Returns

string|null

getUserAgent()

getUserAgent() : string|null

Retrieve the User-Agent.

Returns

string|null —

The user agent if it's set.

setDetectionType()

setDetectionType(string  $type = null) 

Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED. 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::DETECTION_TYPE_MOBILE.

getMatchingRegex()

getMatchingRegex() 

getMatchesArray()

getMatchesArray() 

getPhoneDevices()

getPhoneDevices() : array

Retrieve the list of known phone devices.

Returns

array —

List of phone devices.

getTabletDevices()

getTabletDevices() : array

Retrieve the list of known tablet devices.

Returns

array —

List of tablet devices.

getUserAgents()

getUserAgents() : array

Alias for getBrowsers() method.

Returns

array —

List of user agents.

getBrowsers()

getBrowsers() : array

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

Returns

array —

List of browsers / user agents.

getUtilities()

getUtilities() : array

Retrieve the list of known utilities.

Returns

array —

List of utilities.

getMobileDetectionRules()

getMobileDetectionRules() : array

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

Returns

array —

All the rules (but not extended).

getMobileDetectionRulesExtended()

getMobileDetectionRulesExtended() : array

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.

Returns

array —

All the rules + extended.

getRules()

getRules() : array

Retrieve the current set of rules.

Returns

array

getOperatingSystems()

getOperatingSystems() : array

Retrieve the list of mobile operating systems.

Returns

array —

The list of mobile operating systems.

checkHttpHeadersForMobile()

checkHttpHeadersForMobile() : boolean

Check the HTTP headers for signs of mobile.

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

Returns

boolean

__call()

__call(string  $name, array  $arguments) : mixed

Magic overloading method.

Parameters

string $name
array $arguments

Throws

\um\lib\mobiledetect\BadMethodCallException

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

Returns

mixed

isMobile()

isMobile(null  $userAgent = null, null  $httpHeaders = null) : boolean

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

Returns

boolean

isTablet()

isTablet(string  $userAgent = null, array  $httpHeaders = null) : boolean

Check if the device is a tablet.

Return true if any type of tablet device is detected.

Parameters

string $userAgent

deprecated

array $httpHeaders

deprecated

Returns

boolean

is()

is(string  $key, string  $userAgent = null, string  $httpHeaders = null) : boolean|integer|null

This method checks for a certain property in the userAgent.

Parameters

string $key
string $userAgent

deprecated

string $httpHeaders

deprecated

Returns

boolean|integer|null

match()

match(  $regex, string  $userAgent = null) : boolean

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

Returns

boolean

getProperties()

getProperties() : array

Get the properties array.

Returns

array

prepareVersionNo()

prepareVersionNo(string  $ver) : float

Prepare the version number.

Parameters

string $ver

The string version, like "2.6.21.2152";

Returns

float

version()

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

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::VERSION_TYPE_STRING to get a string value or self::VERSION_TYPE_FLOAT indicating a float value. This parameter is optional and defaults to self::VERSION_TYPE_STRING. Passing an invalid parameter will default to the this type as well.

Returns

string|float —

The version of the property we are trying to extract.

mobileGrade()

mobileGrade() : string

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

Returns

string —

One of the self::MOBILEGRADE* constants.

matchDetectionRulesAgainstUA()

matchDetectionRulesAgainstUA(null  $userAgent = null) : boolean

Find a detection rule that matches the current User-agent.

Parameters

null $userAgent

deprecated

Returns

boolean

matchUAAgainstKey()

matchUAAgainstKey(string  $key, null  $userAgent = null) : mixed

Search for a certain key in the rules array.

If the key is found the try to match the corresponding regex agains the User-Agent.

Parameters

string $key
null $userAgent

deprecated

Returns

mixed