Transfering data to new sessions

Sorry if this has already been asked before I couldn’t find anything related. Right now what I am trying to do is keep information passing from session to session. Example, actionOne -> actionTwo -> actionThree … Now I need to use the same kinds of information in each action but nothing is kept sacred so to speak. I have tried a few things, but I think my lack of understanding the big picture is causing me to not find my solution.

actionOne passes an accountID, actionTwo uses accountID to find directory and saves data, actionThree opens directory and reads data… so I need to keep a few parameters intact through the app. Any idea would be great, thank you. Oh yea please feel free to talk like I’m dumb I am new to this stuff. Thank you in advance.

See: user->setState and getState.




//actionOne 

Yii::app()->user->setState('accountId',123);

...


//actionTwo

$accountId = Yii::app()->user->getState('accountId');




I appreciate that but it doesn’t seem to work and I am not sure why… I do something like this.




//actionOne

Yii::app()->user->setState('acctID', $acctID);


//actionTwo

$id = Yii::app()->user->getState('acctID');

if(!file_exists("path/to/create/$id"))

   mkdir("path/to/create/$id", 0777, true);



I also attempted to get it in another action and same thing nothing seems to happen. I echoed the variables, it is just empty as it nothing was filled there, but not null. Any ideas why this is happening?

EDIT*** If I do an echo where I setState I get the expected output just not in another action.

Are there any other suggestions I cannot seem to find a way to do this, I would think it would be possible.

Hmm, please try:


$id = Yii::app()->user->acctID;

Good luck :)

Nope that doesn’t seem to work either!! Any other ideas here?

Seems to be a generally problem with your session handling.

Maybe you have different session-ids in action one and two (because of different hosts in the url: 192.168…, localhost, 127.0.0.1 …).

Check your php-sessions:

  • If you work on your local workstation you can take a look at the session files in the configured directory.

  • try like below:




//actionOne

Yii::app()->user->setState('acctID', $acctID);

var_dump($_SESSION);

echo 'sessionid=' . session_id();


//actionTwo

session_start();

var_dump($_SESSION);

echo 'sessionid=' . session_id();


$id = Yii::app()->user->getState('acctID');

if(!file_exists("path/to/create/$id"))

   mkdir("path/to/create/$id", 0777, true);




I just checked and the sessionID is the same on each action I use…

  • And what is with the content in the session in actionOne/Two

  • Is ‘xxxxxacctID’ (setState adds a prefix) listed in the $_SESSION on var_dump?

Did you check set/read values from the session with PHP standard code? Does this work?

actionOne

$_SESSION[‘accId’]=123 …

actionTwo

echo $_SESSION[‘accId’];

It turns out one of my actions when done in the intended sequence actually gets created as a new session, so I had to create a work around for that. I think I got it now, thank you for all your help.