Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP redirect to previous URL after login

Tags:

php

cakephp

I am using CakePHP 2.2.0, When a user is not logged in, when a link is clicked, it goes to the login page, after login i would like to redirect to the initial link that was clicked. Anybody knows how we can implement it using CakePHP? I tried with the $this->referer() but it seems not getting the previously visited URL. If anybody knows please help me to sort out!

like image 665
Royal Avatar asked Nov 28 '22 01:11

Royal


2 Answers

If you need to redirect to the referer page you can use:

$this->redirect($this->referer());

Reference: http://book.cakephp.org/2.0/en/controllers.html#flow-control

like image 89
Do Nhu Vy Avatar answered Nov 30 '22 14:11

Do Nhu Vy


In the method processing the login, you could redirect to

$this->Auth->redirectUrl()
like image 38
Klaus Avatar answered Nov 30 '22 15:11

Klaus