cakephp redirecting to previous page after login

function checkSession() {
// If the session info hasn't been set...
if (!$this->Session->check('User')) {
$this->Session->write('login_referrer',$this->params['url']['url']);
// Force the user to login
$this->redirect('/users/login');
exit();
}
}

 

if ($success) {
if ($this->Session->check(’login_referrer’)) {
$loginReferrer = $this->Session->read(’login_referrer’);
$this->Session->delete(’login_referrer’);
$this->redirect($loginReferrer);
return true;
}
// the line before is the original redirect code
$this->Auth->redirect(’login_success’);
return true;
}

 

echo $this->Html->link('Login', '/login?redirect='.$this->here);

echo $this->Form->input('redirect', array('type' => 'hidden', 'value' => $this->request->query['redirect']));

if (isset($this->request->data['User']['redirect'])) {
    $this->redirect( $this->request->data['User']['redirect'] );
} else {
    $this->redirect( $this->Auth->redirectUrl() );
}

 

2 thoughts on “cakephp redirecting to previous page after login

Leave a Reply

Your email address will not be published. Required fields are marked *