Welcome Guest, Not a member yet? Register   Sign In
CI session userdata not persisting through requests
#1

[eluser]diego.greyrobot[/eluser]
Hello all, I'm totally perplexed by this problem. Basically in the controller function (checkout) that sets the userdata, i have these lines (with debugging statements included)...
Code:
$data = array('user' => urldecode($httpParsedResponseAr['FIRSTNAME']).' '.urldecode($httpParsedResponseAr['LASTNAME']),
    'email' => urldecode($httpParsedResponseAr['EMAIL']),
    'street' => urldecode($street1).' '.urldecode($street2),
    'city' => urldecode($city_name),
    'state' => urldecode($state_province),
    'zip' => urldecode($postal_code),
    'payer_id' => urldecode($payerID),
    'token' => $token);
            
     $this->session->sess_create();
     $this->session->set_userdata($data);

     die($this->session->userdata('token'));

//outputs: EZ-1002321 etc...
the userdata is echoed out just fine when this code runs. After which the view loads with a form so the visitor can confirm the order details and hit checkout. The form submits the data to my next controller function (process_order) which is supposed to receive two very important variables from session userdata: token and payer_id. but i always get an error saying that those are missing, so i placed the same die statement at the top of the process_order function and in fact there is nothing in $this->session->userdata('token') or payer_id, even though it existed in the previous function. I checked that there are no other variables that might overwrite those values.

I'm using ci_sessions in a database and also tried it the default way. it works fine but the userdata field in the db is empty even though i can echo out the value of $this->session->userdata('token or whatever') within the function the set that data.

What could cause the data to be lost after a one or two requests? the code is a bit long and messy but i can include that if it helps.
#2

[eluser]pistolPete[/eluser]
Why are you calling this function manually?
Code:
$this->session->sess_create();

It's executed in the sessions class constructor:
Code:
function CI_Session($params = array())
{
(...)
        // Run the Session routine. If a session doesn't exist we'll
        // create a new one.  If it does, we'll update it.
        if ( ! $this->sess_read())
        {
            $this->sess_create();
        }
        else
        {
            $this->sess_update();
        }
(...)

Try removing it from your code and check if it's working.
#3

[eluser]TheFuzzy0ne[/eluser]
First of all, before you post any code, I would like to suggest that you attempt to give it a clean up. You just might find your problem. I'm wondering if this is a database encoding issue. What's the table encoding set to?
#4

[eluser]diego.greyrobot[/eluser]
to pistolPete: Yeah i also tried removing it.

to FuzzyOne: (hi again) The db is set to utf8 and the table collation is ascii_general_ci (i used the sql script from the CI userguide) but i had the same problem before when using the normal session setup, cookies i believe?

I did clean the code up as much as i could, removing any unused variables and checking for identifier collisions. it's messy only in the sense that there's comments everywhere and not everything is neatly spaced or tabbed.

I switched to using php sessions for now... any other suggestions? Thanks for the quick replies guys!
#5

[eluser]TheFuzzy0ne[/eluser]
I'm sure it shouldn't make a difference, but my collation is utf8_unicode_ci. You might want to give it a go.

I seemed to have a problem at some point where a character such as a back slash, was breaking things. I never got to the bottom of it, but I'd suggest printing out the whole userdata array, and seeing if you can spot anything that looks suspicious.

Failing that, please post your code, although I suspect it's not your code that's to blame, but rather a character breaking the userdata array.

EDIT: One more thing. I seem to remember you using $_SESSION directly, and calling session_start() in your code. I'd suggest you stick to using CodeIgniters userdata methods, and search for session_start() in your code and remove any occurances, as that will no doubt be causing a problem.
#6

[eluser]diego.greyrobot[/eluser]
Awesome, there was a back slash in one of the array values. Thanks FuzzyOne!
#7

[eluser]fireproofsocks[/eluser]
This is an old thread, but this is essentially the exact problem I'm having, except I'm not using a database:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

I have set the $config['encryption_key'] value, but the session data just does not persist between requests.




Theme © iAndrew 2016 - Forum software by © MyBB