Class that helps identifying the device or type of device that made the request.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Searches for a string in the user agent string.
| Type | Description |
|---|---|
| array | Array of strings to look for |
boolean
protected static function find($what)
{
if(isset($_SERVER['HTTP_USER_AGENT']))
{
foreach($what as $find)
{
if(stripos($_SERVER['HTTP_USER_AGENT'], $find) !== false)
{
return true;
}
}
}
return false;
}
Converts the HTTP_ACCEPT headers into an array.
| Type | Description |
|---|---|
| string | Array key |
| string | (optional) String to look for |
mixed
protected static function accept($header, $what = null)
{
if(isset($_SERVER[$header]))
{
$accepts = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER[$header]))));
if($what === null && !empty($accepts))
{
return $accepts;
}
else
{
return in_array(strtolower($what), $accepts);
}
}
return false;
}
Returns true if the user agent that made the request is identified as a mobile device.
boolean
public static function isMobile()
{
return static::find(Config::get('user_agents.mobiles'));
}
Returns true if the user agent that made the request is identified as a robot/crawler.
boolean
public static function isRobot()
{
return static::find(Config::get('user_agents.robots'));
}
Returns TRUE if the string you're looking for exists in the user agent string and FALSE if not.Can be used to detect the type of device (UserAgent::is('iphone') or UserAgent::is(array('iphone', 'ipod'))).
| Type | Description |
|---|---|
| mixed | String or array of strings you're looking for |
boolean
public static function is($device)
{
return static::find((array) $device);
}
Returns list of accepted content types or boolean value if you are looking for a content type.
| Type | Description |
|---|---|
| string | (optional) Language to look for. |
mixed
public static function accepts($content = null)
{
return static::accept('HTTP_ACCEPT', $content);
}
Returns list of accepted languages or boolean value if you are looking for a language.
| Type | Description |
|---|---|
| string | (optional) Language to look for. |
mixed
public static function acceptsLanguage($language = null)
{
return static::accept('HTTP_ACCEPT_LANGUAGE', $language);
}
Returns list of accepted character sets or boolean value if you are looking for a character set.
| Type | Description |
|---|---|
| string | (optional) Character set to look for. |
mixed
public static function acceptsCharset($charset = null)
{
return static::accept('HTTP_ACCEPT_CHARSET', $charset);
}
Returns list of accepted encodings or boolean value if you are looking for an encoding.
| Type | Description |
|---|---|
| string | (optional) Language to look for. |
mixed
public static function acceptsEncoding($encoding = null)
{
return static::accept('HTTP_ACCEPT_ENCODING', $encoding);
}