Agent Class
The agent class allows you to retrieve information about browser type, version, platform or operating system, etc, based on the clients User Agent string.
Usage
Check if the current browser accepts a specific character set.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$charset |
string |
Name of the characterset |
|
Returns |
boolean |
Example |
if (Agent::accepts_charset('iso-8859-1'))
{
echo "Yes, the browser accepts this characterset!";
}
|
Check if the current browser accepts a specific ISO language code.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$language |
string |
ISO language code |
|
Returns |
boolean |
Example |
if (Agent::accepts_language('nl_BE'))
{
echo "Yes, the browser is configured for the Flemish language!";
}
|
Returns the normalized browser name from the user agent string.
Static |
Yes |
Parameters |
None |
Returns |
string |
Example |
switch (Agent::browser())
{
case 'Firefox':
break;
case 'IE':
break;
case 'Chrome':
break;
case 'Unknown':
break;
default:
break;
}
|
Returns the normalized platform name from the user agent string.
Static |
Yes |
Parameters |
None |
Returns |
string |
Example |
switch (Agent::platform())
{
case 'Win95':
case 'Win98':
case 'WinNT':
case 'WinME':
case 'Win2000':
break;
case 'WinXP':
case 'WinVista':
case 'Win7':
break;
case 'Linux':
break;
case 'MacOSX':
case 'MacPPC':
break;
case 'SunOS':
case 'FreeBSD':
case 'Debian':
case 'HP-UX':
case 'IRIX64':
break;
case 'unknown':
break;
default:
break;
}
|
Returns the browser version.
Static |
Yes |
Parameters |
None |
Returns |
float |
Example |
if (Agent::browser() == 'IE' and Agent::version() < 7)
{
echo "Sorry, no support for outdated browsers!";
}
|
Returns an array with all charactersets accepted by the browser.
Static |
Yes |
Parameters |
None |
Returns |
array |
Example |
$sets = Agent::charsets();
if (in_array('iso-8859-1', $sets))
{
echo "Yes, the browser accepts this characterset!";
}
|
Returns an array with all ISO languages accepted by the browser.
Static |
Yes |
Parameters |
None |
Returns |
array |
Example |
$lang = Agent::languages();
if (in_array('nl_BE', $lang))
{
echo "Yes, the browser is configured for the Flemish language!";
}
|
Returns an array with all properties of the detected browser.
Static |
Yes |
Parameters |
None |
Returns |
array |
Example |
$properties = Agent::properties();
|
Return a specific browser property. See properties() for the list of supported properties.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$property |
string |
Name of the property to retrieve. The name is case-sensitive! |
|
Returns |
mixed |
Example |
if (Agent::property('cookies') === true)
{
echo "Yes, the browser supports Cookies!";
}
|
Checks if the browser used is running on a mobile device.
Static |
Yes |
Parameters |
None |
Returns |
boolean |
Example |
if (Agent::is_mobiledevice())
{
$content = View::forge('mobile/viewname');
}
else
{
$content = View::forge('standard/viewname');
}
|
Checks if the browser agent indicates the visitor is a robot or crawler.
Static |
Yes |
Parameters |
None |
Returns |
boolean |
Example |
if (Agent::is_robot())
{
$content = View::forge('robot/viewname');
}
else
{
$content = View::forge('standard/viewname');
}
|