Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (33 sloc) 1 KB


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


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


Install as an application component, in your config:

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


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;