WpvMobileDetect

Mobile Detect Library =====================

Motto: "Every business should have a mobile detection script to detect mobile readers"

WpvMobileDetect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

author

Current authors: Serban Ghita serbanghita@gmail.com, Nick Ilyin nick.ilyin@gmail.com

         Original author: Victor Stanciu <vic.stanciu@gmail.com>
license

Code and contributions have 'MIT License'

         More details: https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
link

http://mobiledetect.net

         GitHub Repo:  https://github.com/serbanghita/Mobile-Detect
         Google Code:  http://code.google.com/p/php-mobile-detect/
         README:       https://github.com/serbanghita/Mobile-Detect/blob/master/README.md
         HOWTO:        https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples
version 2.7.7

Methods

Get an instance of this class

get_instance() 
static

Construct an instance of this class.

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

Arguments

$headers

array

Specify the headers as injection. Should be PHP _SERVER flavored.

                  If left empty, will use the global _SERVER['HTTP_*'] vars instead.

$userAgent

string

Inject the User-Agent header. If null, will use HTTP_USER_AGENT

                     from the $headers array instead.

Get the current script version.

getScriptVersion() : string
static

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

Response

string

The version number in semantic version format.

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

setHttpHeaders(array $httpHeaders = null) 

Arguments

$httpHeaders

array

The headers to set. If null, then using PHP's _SERVER to extract

                      the headers. The default null is left for backwards compatibilty.

Retrieves the HTTP headers.

getHttpHeaders() : array

Response

array

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

getHttpHeader(string $header) : string|null

Simply null is returned.

Arguments

$header

string

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.

Response

string|null

The value of the header.

getMobileHeaders

getMobileHeaders() 

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

getUaHttpHeaders() : array

Response

array

List of HTTP headers.

Set the User-Agent to be used.

setUserAgent(string $userAgent = null) 

Arguments

$userAgent

string

The user agent string to set.

Retrieve the User-Agent.

getUserAgent() : string|null

Response

string|null

The user agent if it's set.

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

setDetectionType(string $type = null) 
deprecated

since version 2.6.9

Arguments

$type

string

The type. Must be a self::DETECTIONTYPE* constant. The default

                parameter is null which will default to self::DETECTION_TYPE_MOBILE.

Retrieve the list of known phone devices.

getPhoneDevices() : array
static

Response

array

List of phone devices.

Retrieve the list of known tablet devices.

getTabletDevices() : array
static

Response

array

List of tablet devices.

Alias for getBrowsers() method.

getUserAgents() : array
static

Response

array

List of user agents.

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

getBrowsers() : array
static

Response

array

List of browsers / user agents.

Retrieve the list of known utilities.

getUtilities() : array
static

Response

array

List of utilities.

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

getMobileDetectionRules() : array
static
deprecated

since version 2.6.9

Response

array

All the rules (but not extended).

Method gets the mobile detection rules + utilities.

getMobileDetectionRulesExtended() : array

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.

deprecated

since version 2.6.9

Response

array

All the rules + extended.

Retrieve the current set of rules.

getRules() : array
deprecated

since version 2.6.9

Response

array

Retrieve the list of mobile operating systems.

getOperatingSystems() : array
static

Response

array

The list of mobile operating systems.

Check the HTTP headers for signs of mobile.

checkHttpHeadersForMobile() : bool

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

Response

bool

Magic overloading method.

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

boolean is...

throws

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

Arguments

$name

string

$arguments

array

Response

mixed

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

matchDetectionRulesAgainstUA(null $userAgent = null) : boolean

Arguments

$userAgent

null

deprecated

Response

boolean

Search for a certain key in the rules array.

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

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

Arguments

$key

string

$userAgent

null

deprecated

Response

mixed

Check if the device is mobile.

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

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

Arguments

$userAgent

null

deprecated

$httpHeaders

null

deprecated

Response

bool

Check if the device is a tablet.

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

Return true if any type of tablet device is detected.

Arguments

$userAgent

string

deprecated

$httpHeaders

array

deprecated

Response

bool

This method checks for a certain property in the userAgent.

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

: The httpHeaders part is not yet used.

Arguments

$key

mixed

$userAgent

string

deprecated

$httpHeaders

string

deprecated

Response

bool|int|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.

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

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

todo

: search in the HTTP headers too.

Arguments

$regex

mixed

$userAgent

string

Response

bool

Get the properties array.

getProperties() : array
static

Response

array

Prepare the version number.

prepareVersionNo(string $ver) : float
todo

Remove the error supression from str_replace() call.

Arguments

$ver

string

The string version, like "2.6.21.2152";

Response

float

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

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

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

Arguments

$propertyName

string

The name of the property. See self::getProperties() array

                         keys for all possible properties.

$type

string

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.

Response

string|float

The version of the property we are trying to extract.

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

mobileGrade() : string

Response

string

One of the self::MOBILEGRADE* constants.

Constants

Mobile detection type.

DETECTION_TYPE_MOBILE
deprecated

since version 2.6.9

Extended detection type.

DETECTION_TYPE_EXTENDED
deprecated

since version 2.6.9

A frequently used regular expression to extract version #s.

VER
deprecated

since version 2.6.9

Top-level device.

MOBILE_GRADE_A

Mid-level device.

MOBILE_GRADE_B

Low-level device.

MOBILE_GRADE_C

Stores the version number of the current release.

VERSION

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

VERSION_TYPE_STRING

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

VERSION_TYPE_FLOAT

Properties

The User-Agent HTTP header is stored in here.

userAgent : string
var

Type(s)

string

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

httpHeaders : array
var

Type(s)

array

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

detectionType : string
deprecated

since version 2.6.9

var

Type(s)

string

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

mobileHeaders : array
static
var

Type(s)

array

List of mobile devices (phones).

phoneDevices : array
static
var

Type(s)

array

List of tablet devices.

tabletDevices : array
static
var

Type(s)

array

List of mobile Operating Systems.

operatingSystems : array
static
var

Type(s)

array

List of mobile User Agents.

browsers : array
static
var

Type(s)

array

Utilities.

utilities : array
static
var

Type(s)

array

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

uaHttpHeaders : array
static
var

Type(s)

array

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

properties : array
static
var

Type(s)

array

instance

instance : 
static