I have the following code in my login method:
if(!(empty($this->data)) && $this->Auth->user())
{
if($this->referer(array('controller' => 'users', 'action' => 'login')))
{
$this->redirect(array('controller' => 'home', 'action' => 'index'));
}
else
{
$this->redirect($this->Auth->redirect($this->referer()));
}
}
}
This basically redirects the user to their previous page when they successfully login using a login form in the site header BUT if they login directly from the login page it will send them to the home page as they previous page would be the login form.
The problem however is that if a user visits a page that requires authentication then they will be redirected to the login page and then login but because they have now visited the login page they will be redirected to the home page and NOT their previous page that they were trying to access.
How do I fix this problem?
Thanks
If I remember correctly (not confirmed on 1.3), you can set the default redirect to home
and check whether the redirect path is set by the Auth component.
Something like this in your login action
$auth_redirect = $this->Session->read("Auth.redirect");
if(isset($auth_redirect) && $auth_redirect != "") {
$this->redirect($auth_redirect);
} else {
$this->redirect('/home/index')
}
And something like this in your app_controler
$this->Auth->loginRedirect = array('controller' => 'home', 'action' => 'index');
There are two or three options, one which is much better in my opinion
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.