Jump to content

Archived

This topic is now archived and is closed to further replies.

c_pattle

Codeigniter session array

Recommended Posts

In my core controller I'm trying to create an array of the user's history.  I am creating an array and then setting the key as the time and the value as the page URL.  However the problem that I'm having is that the previous array seems to get overwritten so there is only ever one key and value pair in the array. 

 

How can I do it so that instead each page will get appended to the array

 

$history = array(
    time() => curPageURL()
);

$this->session->set_userdata('history', $history);

 

Thanks for any help

Share this post


Link to post
Share on other sites

I'm not a code ignitor user, but something like:

 

$this->session->set_userdata('history', array_merge($this->session->get_userdata('history', $history));

 

should do the trick.

Share this post


Link to post
Share on other sites

How far back do you want to go?  I have current and previous set up like this:

 

// Set the current URL the user was browsing
$this->session->set_userdata('previous', $this->session->userdata('current'));

// Set the current URL the user is browsing
$this->session->set_userdata('current', uri_string());

 

Not sure what exactly you're interested in doing, but I've written a tracker in CI that marks the controller + method + slug by user_id and is quite effective for marking things as "new" or not.  If interested I can post links to my github.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.