CodeIgniter Forums
How shall I record the last page the user was on? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How shall I record the last page the user was on? (/showthread.php?tid=12657)



How shall I record the last page the user was on? - El Forum - 10-27-2008

[eluser]KeyStroke[/eluser]
Hi,

I have some protected pages on my site that only members can access. I want to code my application so that, when a non-member tries to access any of those pages, he will be sent to a login page. Once he logins successfully, he will be sent back to the page he was trying to access.

I've tried the following:
Code:
function login()
    {
        $view_data = array();
        
        $this->session->set_userdata(array('last_visited_page' => $_SERVER['HTTP_REFERER']));

/*
Authentication and some code goes here
*/

// if login is successful, redirect to last page
redirect($this->session->userdata('last_visited_page'));

The problem with this code is if the login wasn't successful, the "last_visited_page' would be the login page itself, which I don't want. I can let every restricted page (function) tell set the session data itself, but that would be a lot of code.

Any ideas?


How shall I record the last page the user was on? - El Forum - 10-27-2008

[eluser]bigtimslim[/eluser]
Maybe don't change last_page_visited if the referer is login


How shall I record the last page the user was on? - El Forum - 10-27-2008

[eluser]KeyStroke[/eluser]
Oh man. I can't believe I didn't think of this!!!

Thanks bigtimslim. I think I should go to sleep now.