Welcome Guest, Not a member yet? Register   Sign In
how to back to the lastpage that we opened after login
#14

[eluser]Santiago Dimattía[/eluser]
- Flashdata will be resetted if you open another page AFTER the redirect to the login.
- Userdata will be rewrite if you open another protected page.

----

To do this I use something like this:

Protected page
Code:
<?php

class Test extends Controller {

    function Test()
    {
        parent::Controller();
        //$this->load->library('session');
    }
    
    function index()
    {

        if($this->auth->is_logged_in()){
            $data['text'] = 'welcome!';
            $this->load->view('test', $data);
        }
        else
        {
            //$this->session->set_flashdata('referer', $this->uri->uri_string());
            $data['url_to_redirect'] = $this->uri->uri_string();
            $this->load->view('login', $data);
        }

    }
}

The login view:

Code:
<html>
<head>
<title>Test page</title>
</head>
<body>

    <form method="post" action="/login/">
        <input type="hidden" value="<?php echo $url_to_redirect; ?>" name="url" id="url" />
        <input type="text" value="Your username" name="username" id="username" /><br />
        <input type="text" value="Your password" name="password" id="password" /><br />
        <input type="submit" value="Login" />
    </form>

</body>
</html>

And login controller:
Code:
<?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();
    }
    
    function index()
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $url_to_redirect = $this->input->post('url');

        if($this->auth->login($username, $password)){
            redirect($url_to_redirect);
        }
        else
        {
            $this->load->view('loginfail');
        }

    }
}

* Code not tested *


Messages In This Thread
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 01:37 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 01:39 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 01:48 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 01:58 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 02:00 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 02:02 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 02:42 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 02:44 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 05:01 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 05:03 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 05:10 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 07:33 AM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 08:02 PM
how to back to the lastpage that we opened after login - by El Forum - 05-08-2009, 08:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB