The mobile application makes Ajax requests to the site on Yii 1.x. In Yii, for each such request, a new user session starts, because the mobile application does not know how to store a COOKIE to send PHPSESSID to the site.

How to make sure that when requests from the mobile application session in Yii did not start? At the same time, I know how to determine exactly the requests from the mobile application. The question is about stopping the session mechanism!

By the way, sessions are stored in the database, the configuration is as follows:

'session' => array( 'timeout' => 32400, // 9 часов 'class' => 'system.web.CDbHttpSession', 'connectionID' => 'db', 'sessionTableName' => 'session', ), 

    2 answers 2

    Override the class, and turn off the autostart session under a certain condition:

     class DbHttpSession extends CDbHttpSession{ public function init() { if($this->isMobile()){ $this->autoStart = false; } parent::init(); } public function isMobile(){ //... return true; } //... } 

    Specify your class in the configuration file:

     'session' => array( 'class' => 'application.components.DbHttpSession', //... ), 
    • Did everything as you wrote, did not work! Session is created .. - Enshtein
    • Moreover, I did the following in public function init () in CHttpSession: var_dump ($ this-> autoStart); - false, i.e. logically, everything should have worked as you wrote, ann is not .. - Enshtein

    The solution is to override the init () method of the CWebUser class:

     class WebUser extends CWebUser { public function init() { if ($this->isMobile()) { return true; } else { parent::init(); } }