flash callback eats session

I wtote the attached EUploadify widget, which encapsulates the jquery/swf Uploadify widget.

This works fine, but for one thing. When the flash uploader calls the PHP Callback function

it seems that the Session data is lost.

I can pass the session_id and/or session_name in the scriptData var of the widget. However how do I

reload it once I’ve retrieved this from $_POST?




if(!Yii::app()->getSession()->getIsStarted()) 

{   

  Yii::app()->getSession()->open();

  $this->log('DN SessionId: ' . Yii::app()->getSession()->sessionID); 

}

else

Yii::app()->getSession()->setSessionID($_POST['session']);



Does not work.

I’m dumb… This works:




if(!Yii::app()->getSession()->getIsStarted()) 

{ 

  Yii::app()->session->sessionID = $_POST['PHPSESSID'];

  Yii::app()->session->open();

}



Also there is a config file solution (from this forum post (in russian)):




        // application components

        'components'=>array(

                'session'=>array(

                        'class'=>'CHttpSession',

                        'useTransparentSessionID'   =>($_POST['PHPSESSID']) ? true : false,

                        'cookieMode'                =>($_POST['PHPSESSID']) ? 'none' : 'allow',

                ),



Also there is already uploadify wrapper extension here.

I know, but wanted a cleaner ‘code’ only solution where I could set all options in the widget. Which is why I wrote Euploadify.

this solution worked for me:


        // application components

        'components'=>array(

                'session'=>array(

                        'class'=>'CHttpSession',

                        'useTransparentSessionID'   =>($_POST['PHPSESSID']) ? true : false,

                        'cookieMode'                =>($_POST['PHPSESSID']) ? 'none' : 'allow',

                ),

I can’t get this to work. I can access the $_POST[‘PHPSESSID’] in the script but using the script below;

if(!Yii::app()->getSession()->getIsStarted())

{

Yii::app()->session->sessionID = $_POST[‘PHPSESSID’];

Yii::app()->session->open();

}

in my controller I can’t seem to access Yii::app()->user->getId() nor can I get passed any accessRules() that pertain to a user role or logged in user for that matter. I’m using the 1.1.4 version of Yii.

Any Ideas?

Cheers,

Sn0rcha

I am using 1.1.4 as well and can’t get it to work either.

Yii::app()->getSession()->getIsStarted() will just return true.

I tried setting autoStart to false in my config/main.php file but with no result

You need to set session id before yii start session itself.

I done this by setting session id in the index.php:




// change the following paths if necessary

$yii=dirname(__FILE__).'/../yii/yii.php';

$config=dirname(__FILE__).'/protected/config/main.php';


// remove the following line when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);


require_once($yii);


if (isset($_POST["PHPSESSID"]) && !empty($_POST["PHPSESSID"])) {

    session_id($_POST["PHPSESSID"]);

    session_start();

} else if (isset($_GET["PHPSESSID"]) && !empty($_GET["PHPSESSID"])) {

    session_id($_GET["PHPSESSID"]);

    session_start();

}


Yii::createWebApplication($config)->run();



Try this in the beginning of the entry-script:




if (isset($_POST['PHPSESSID']))

{

  $_COOKIE['PHPSESSID'] = $_POST['PHPSESSID'];

}

The session component will then read the correct session id from the cookie as usual.

Thanks this work perfectly.

I put it at the top of the controller action first but then it’s called too late.

it gave a 302 error redirecting to the loginpage because the accessRules function is called before the controller action.

I put it into the module’s init() function and it works great.

Thank you very much i did search for the solution for one whole day…

Thank to Jesus at last i find this…