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

accepts_charset($charset = 'utf-8')

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
// Check if the users browser accepts iso-8859-1
if (Agent::accepts_charset('iso-8859-1'))
{
	echo "Yes, the browser accepts this characterset!";
}
	

accepts_language($language = 'en')

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
// Check if the users browser accepts Flemish (Belgian Dutch)
if (Agent::accepts_language('nl_BE'))
{
	echo "Yes, the browser is configured for the Flemish language!";
}
	

browser()

Returns the normalized browser name from the user agent string.

Static Yes
Parameters None
Returns string
Example
// Process based on the browser name
switch (Agent::browser())
{
	case 'Firefox':
		// do something specific here
		break;
	case 'IE':
		// do something specific here
		break;
	case 'Chrome':
		// do something specific here
		break;
	case 'Unknown':
		// do something specific here
		break;
	default:
		// these are not all supported browser...
		break;
}

platform()

Returns the normalized platform name from the user agent string.

Static Yes
Parameters None
Returns string
Example
// Process based on the browser platform
switch (Agent::platform())
{
	case 'Win95':
	case 'Win98':
	case 'WinNT':
	case 'WinME':
	case 'Win2000':
		// do something specific here
		break;
	case 'WinXP':
	case 'WinVista':
	case 'Win7':
		// do something specific here
		break;
	case 'Linux':
		// do something specific here
		break;
	case 'MacOSX':
	case 'MacPPC':
		// do something specific here
		break;
	case 'SunOS':
	case 'FreeBSD':
	case 'Debian':
	case 'HP-UX':
	case 'IRIX64':
		// do something specific here
		break;
	case 'unknown':
		// do something specific here
		break;
	default:
		// these are not all supported platforms...
		break;
}

version()

Returns the browser version.

Static Yes
Parameters None
Returns float
Example
// Check if an old Internet Explorer version is used
if (Agent::browser() == 'IE' and Agent::version() < 7)
{
	echo "Sorry, no support for outdated browsers!";
}
	

charsets()

Returns an array with all charactersets accepted by the browser.

Static Yes
Parameters None
Returns array
Example
// Check if the users browser accepts iso-8859-1
$sets = Agent::charsets();
if (in_array('iso-8859-1', $sets))
{
	echo "Yes, the browser accepts this characterset!";
}
	

languages()

Returns an array with all ISO languages accepted by the browser.

Static Yes
Parameters None
Returns array
Example
// Check if the users browser accepts Flemish (Belgian Dutch)
$lang = Agent::languages();
if (in_array('nl_BE', $lang))
{
	echo "Yes, the browser is configured for the Flemish language!";
}
	

properties()

Returns an array with all properties of the detected browser.

Static Yes
Parameters None
Returns array
Example
// Get the browser properties
$properties = Agent::properties();

/**
 * These are the supported properties, and their default value
 *
 * $properties = array(
 * 	'browser'             => "unknown",
 * 	'version'             => 0,
 * 	'majorver'            => 0,
 * 	'minorver'            => 0,
 * 	'platform'            => 'unknown',
 * 	'alpha'               => false,
 * 	'beta'                => false,
 * 	'win16'               => false,
 * 	'win32'               => false,
 * 	'win64'               => false,
 * 	'frames'              => false,
 * 	'iframes'             => false,
 * 	'tables'              => false,
 * 	'cookies'             => false,
 * 	'backgroundsounds'    => false,
 * 	'javascript'          => false,
 * 	'vbscript'            => false,
 * 	'javaapplets'         => false,
 * 	'activexcontrols'     => false,
 * 	'isbanned'            => false,
 * 	'ismobiledevice'      => false,
 * 	'issyndicationreader' => false,
 * 	'crawler'             => false,
 * 	'cssversion'          => 0,
 * 	'aolversion'          => 0,
 * );
 *
 * Note that the booleans indicate a specific supported functionality.
 * It does not indicated if it is enabled or not.
 */

property($property = null)

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
// Check if the browser supports cookies
if (Agent::property('cookies') === true)
{
	echo "Yes, the browser supports Cookies!";
}
	

is_mobiledevice()

Checks if the browser used is running on a mobile device.

Static Yes
Parameters None
Returns boolean
Example
// Load a platform specific view
if (Agent::is_mobiledevice())
{
	$content = View::forge('mobile/viewname');
}
else
{
	$content = View::forge('standard/viewname');
}

is_robot()

Checks if the browser agent indicates the visitor is a robot or crawler.

Static Yes
Parameters None
Returns boolean
Example
// Load a crawler specific view (note: this is frowned upon!)
if (Agent::is_robot())
{
	$content = View::forge('robot/viewname');
}
else
{
	$content = View::forge('standard/viewname');
}