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
|
|---|---|
| license |
Code and contributions have 'MIT License'
|
| link |
|
| version | 2.7.7 |
get_instance()
__construct(array $headers = null, string $userAgent = null)
arraySpecify the headers as injection. Should be PHP _SERVER flavored.
If left empty, will use the global _SERVER['HTTP_*'] vars instead.
stringInject the User-Agent header. If null, will use HTTP_USER_AGENT
from the $headers array instead.
getScriptVersion() : string
This is useful for the demo.php file, so people can check on what version they are testing for mobile devices.
stringThe version number in semantic version format.
setHttpHeaders(array $httpHeaders = null)
arrayThe headers to set. If null, then using PHP's _SERVER to extract
the headers. The default null is left for backwards compatibilty.
getHttpHeaders() : array
array
getHttpHeader(string $header) : string|null
Simply null is returned.
stringThe 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.
string|nullThe value of the header.
getMobileHeaders()
getUaHttpHeaders() : array
arrayList of HTTP headers.
setUserAgent(string $userAgent = null)
stringThe user agent string to set.
getUserAgent() : string|null
string|nullThe user agent if it's set.
setDetectionType(string $type = null)
| deprecated |
since version 2.6.9 |
|---|---|
stringThe type. Must be a self::DETECTIONTYPE* constant. The default
parameter is null which will default to self::DETECTION_TYPE_MOBILE.
getPhoneDevices() : array
arrayList of phone devices.
getTabletDevices() : array
arrayList of tablet devices.
getUserAgents() : array
arrayList of user agents.
getBrowsers() : array
arrayList of browsers / user agents.
getUtilities() : array
arrayList of utilities.
getMobileDetectionRules() : array
| deprecated |
since version 2.6.9 |
|---|---|
arrayAll the rules (but not extended).
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 |
|---|---|
arrayAll the rules + extended.
getRules() : array
| deprecated |
since version 2.6.9 |
|---|---|
array
checkHttpHeadersForMobile() : bool
This is the fastest mobile check possible; it's used inside isMobile() method.
bool
__call(string $name, array $arguments) : mixed
| method |
boolean is... |
|---|---|
| throws |
when the method doesn't exist and doesn't start with 'is' |
string
array
mixed
matchDetectionRulesAgainstUA(null $userAgent = null) : boolean
nulldeprecated
boolean
matchUAAgainstKey(string $key, null $userAgent = null) : mixed
If the key is found the try to match the corresponding regex agains the User-Agent.
string
nulldeprecated
mixed
isMobile(null $userAgent = null, null $httpHeaders = null) : bool
Returns true if any type of mobile device detected, including special ones
nulldeprecated
nulldeprecated
bool
isTablet(string $userAgent = null, array $httpHeaders = null) : bool
Return true if any type of tablet device is detected.
stringdeprecated
arraydeprecated
bool
is(mixed $key, string $userAgent = null, string $httpHeaders = null) : bool|int|null
| todo |
: The httpHeaders part is not yet used. |
|---|
mixed
stringdeprecated
stringdeprecated
bool|int|null
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. |
|---|
mixed
string
bool
getProperties() : array
array
prepareVersionNo(string $ver) : float
| todo |
Remove the error supression from str_replace() call. |
|---|
stringThe string version, like "2.6.21.2152";
float
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)
stringThe name of the property. See self::getProperties() array
keys for all possible properties.
stringEither 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.
string|floatThe version of the property we are trying to extract.
mobileGrade() : string
stringOne of the self::MOBILEGRADE* constants.
DETECTION_TYPE_MOBILE
| deprecated |
since version 2.6.9 |
|---|---|
DETECTION_TYPE_EXTENDED
| deprecated |
since version 2.6.9 |
|---|---|
VER
| deprecated |
since version 2.6.9 |
|---|---|
MOBILE_GRADE_A
MOBILE_GRADE_B
MOBILE_GRADE_C
VERSION
VERSION_TYPE_STRING
VERSION_TYPE_FLOAT
userAgent : string
| var | |
|---|---|
string
httpHeaders : array
| var | |
|---|---|
array
detectionType : string
| deprecated |
since version 2.6.9 |
|---|---|
| var | |
string
mobileHeaders : array
| var | |
|---|---|
array
phoneDevices : array
| var | |
|---|---|
array
tabletDevices : array
| var | |
|---|---|
array
browsers : array
| var | |
|---|---|
array
utilities : array
| var | |
|---|---|
array
uaHttpHeaders : array
| var | |
|---|---|
array
properties : array
| var | |
|---|---|
array
instance :