| Status | Draft |
|---|---|
| Todo | __toString(), Proofread |
This library is deprecated and will no longer be available in Kohana 2.2. It's functionality will move to the Kohana core class.
$this->user_agent = new User_agent;
It can then be accessed through $this→user_agent. All methods in this library rely on data provided by the visitor's webbrowser, so it could be faked.
Checks if the current request is being made by a webbrowser, and returns TRUE if this is the case.
if ($this->User_agent->is_browser() == TRUE) { echo 'Hello browser!'; }
Checks if the current request is begin made by a robot(e.g. a search engine spider), and returns TRUE if this is the case.
if ($this->User_agent->is_robot() == TRUE) { echo 'Hello robot!'; }
Checks if the current request is begin made by a mobile browser(e.g. Pocket IE or Opera mini), and returns TRUE if this is the case.
if ($this->User_agent->is_mobile() == TRUE) { echo 'Hello mobile!'; }
The Accept-Language header specifies in which language the visitor would like his request to be returned. The accept_lang checks the Accept-Language header for the specified language, and returns TRUE if this language is in the Accept-Language Header, anf alse if this is not the case.
if ($this->User_agent->accept_lang('nl') == TRUE) { // Send result in Dutch if accepted echo 'Hallo wereld!'; } else { // Send result in English echo 'Hello world!'; }
The Accept-Charset header specifies the visitor's accepted charsets. The accept_charset function checks if the specified charset is found in this header, and returns TRUE if it is, and FALSE if it isn't.
if ($this->User_agent->accept_charset('utf-8') == TRUE) { echo 'I\'m glad you accept UTF-8 charset!'; } else { echo 'Please start supporting UTF-8'; }
Contains the name of the browser.
// Prints name of the browser on screen (e.g. 'Firefox' or 'Internet Explorer') print Kohana::debug($this->User_agent->browser);
Contains the complete user agent string.
print Kohana::debug($this->User_agent->agent);
It could result in HTML as:
Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Contains the name of the mobile browser, if the request has been made by a mobile device.
print Kohana::debug($this->User_agent->mobile);
It could result in HTML as:
Opera Mini
Contains the browser version.
print Kohana::debug($this->User_agent->version);
It could result in HTML as:
2.0.0.11
Contains the referer string.
print Kohana::debug($this->User_agent->referer);