Welcome Guest, Not a member yet? Register   Sign In
How shall I record the last page the user was on?
#1

[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?
#2

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB