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

[eluser]eoinmcg[/eluser]
[quote author="Dam1an" date="1241798607"]

I've had bad experiences with that, can't remember what I was trying to do, but it either wasn;t always set, or wasn;t always accurate :-S[/quote]

Yeah, if a user fails the login the first time the value of HTTP_REFERER is obviously going to change. So, what I would do then is if the referrer has been POSTED it's populated back into the form. Generally this solution has worked well for me in the past but I'll definitely have a wee look at using flash data.
#12

[eluser]drewbee[/eluser]
As a note, make sure you save the flash data only on the initial display of the login form. If the user enters invalid credentials, you want to make sure 1. You don't overwrite where they originally came from and 2. if you are using flashdata, make sure to call keep_flashdata() to keep it from removing itself.
#13

[eluser]yudahebat[/eluser]
can you give me the example of this function??
help me please, I need for my college project..
thxz before..
#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 *




Theme © iAndrew 2016 - Forum software by © MyBB