Skip to content

roundpartner/yii-detectmobilebrowser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

yii-detectmobilebrowser

Handles detecting mobile browsers. Results are stored locally for caching calls within the same request, and stored in a cookie for caching across requests.

Detection regex used from http://detectmobilebrowsers.com/

Requirements

Tested on Yii 1.1.8 - 1.1.14, should work on all versions.

Installation

Install as an application component, in your config:

'components' => array(
   'detectMobileBrowser' => array(
       'class' => 'ext.yii-detectmobilebrowser.XDetectMobileBrowser',
    ),
),

Install and set http only and secure cookies:

'components' => array(
   'detectMobileBrowser' => array(
       'class' => 'ext.yii-detectmobilebrowser.XDetectMobileBrowser',
       'secure' => true,
       'httpOnly' => true,
    ),
),

Usage

You can get the current user preference like this:

if (Yii::app()->detectMobileBrowser->showMobile) {
    // do something
}

By default it will use the automatically detected value. You can also set the preference yourself like this:

public function actionShowMobile() {
    Yii::app()->detectMobileBrowser->showMobile = true;
    $this->redirect(array('/site/index'));
}

About

handles detecting mobile browsers

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%