Welcome Guest, Not a member yet? Register   Sign In
Losing Session Data
#1

[eluser]derekmichaeljohnson[/eluser]
I have a 2 page registration process, and the data from the first page is stored in an array in the user's session data. To give you an example:

Code:
$pg1 = array(
  'name' => 'John',
  'email' => '[email protected]'
  // etc.
);
$this->session->set_userdata('registration',$pg1);

Then once they complete the second page, the data is merged with the first page and is processed.

All was well, until someone reported an error which was being caused by the data from the first page NOT being present at the time of processing. The details are sketchy, so I can't be certain how long they waited between pages, but I'm going to assume the session data expired.

Could this have something to do with CI refreshing the session information (set to 300 seconds)? The user definitely did NOT wait 2 hours to finish the second page, which is the time set for sessions to expire (in config.php).

Any ideas?
#2

[eluser]treeface[/eluser]
Hm, not sure...perhaps the user has cookies disabled?

<b>edit:</b> Also...have you tried using flashdata? I don't think it should matter, but who knows..
#3

[eluser]derekmichaeljohnson[/eluser]
[quote author="treeface" date="1280356560"]Hm, not sure...perhaps the user has cookies disabled?[/quote]
Unfortunately, no. That was my first guess, too :-)
#4

[eluser]mi6crazyheart[/eluser]
Can u show u'r codes...
#5

[eluser]treeface[/eluser]
Aw damn. Has the user been able to replicate the issue? Have any other users reported it? Is this something you've ever noticed before?
#6

[eluser]derekmichaeljohnson[/eluser]
[quote author="mi6crazyheart" date="1280357334"]Can u show u'r codes...[/quote]
Sure.
Code:
function add()
{
        if(empty($_POST))
        // no post data, show first page
        {
            $this->layout->load('layout','properties/properties_add_view');
        }
        else
        // post data found
        {
            // get prop info from session (if exists)
            $property = ($this->session->userdata('property')) ? $this->session->userdata('property') : array();
            
            // add post data to session
            foreach($_POST as $key=>$val)
            {
                if($key != 'page') // don't include page number
                {
                    $property[$key] = $val;
                }
            }
            $this->session->set_userdata('property',$property);
            
            if($_POST['page']['number'] == 1)
            // show page 2
            {
                $this->layout->load('layout','properties/properties_add_2_sale_view',$data);
            }
            else
            // all finished
            {
                $this->_process_property();
            }
        }
    }
}
  
function _process_property()
{
    $prop = $this->session->userdata('property');
    $prop['user_id'] = $this->session->userdata('id');
    
    // insert record
    $this->db->insert('props',$prop);
    $pid = $this->db->insert_id();
    
    $this->session->unset_userdata('property');
    redirect('dashboard');
}
[quote author="treeface" date="1280357525"]Aw damn. Has the user been able to replicate the issue? Have any other users reported it? Is this something you've ever noticed before?[/quote]
Nope, the user has not experienced it since, and no others have reported problems.
#7

[eluser]treeface[/eluser]
[quote author="derekmichaeljohnson" date="1280357936"]Nope, the user has not experienced it since, and no others have reported problems.[/quote]

Well then harumph, I say. Maybe it was just a glitch in the Matrix. If I were you, I'd keep note of it and wait for it to happen again. I don't immediately see anything wrong with your code.
#8

[eluser]derekmichaeljohnson[/eluser]
[quote author="treeface" date="1280358610"]Well then harumph, I say.[/quote]
Give the governor a HARUMPH!

I'll keep watching it and see what happens. In the meantime, anyone else see any problems?
#9

[eluser]loosetops[/eluser]
I have lost a session variable recently and I couldn't figure out why. Out of about 7 session variables one disappeared. I'm still waiting for it to happen again while still in development.
#10

[eluser]LuckyFella73[/eluser]
In case you didn't check:

be sure that the sess_cookie_name and cookie_prefix (defined in config.php)
have NO underscore (IE issue) and set the cookie domain
like commented in config.php - i.e. ".yourdomain.com"

I read many posts about lost sessions and in most cases
the source of the problem was one of this config lines.

Hope that helps.




Theme © iAndrew 2016 - Forum software by © MyBB