I had a problem returning to the referrer page:
first url: http://site.com/venue/apartments/1564/venue-name referer url: null
On this page, I can edit the material inside, so I have a login button to go to the login page after a successful login, I would like to return to the first url .
second url: http://site.com/users/login referer url: http://site.com/venue/apartments/1564/venue-name
when I try to log in, due to CakePHP rules of action, I need to refresh the login page to verify credentials, here the problem starts:
third url: http://site.com/users/login referer url: http://site.com/users/login
refreshing the page and checking the credentials in the login action of the users controller, I get a link to the same page that I was on before, and now I can’t return to the first url .
I tried some solution by setting a session variable in the AppController, which checks if I am on the login action page and do this:
AppController.php public function beforeFilter () { $this->setRedirect(); } public function setRedirect () { if ($this->request->params['controller'] != 'users' && $this->request->params['action'] != 'login') { $this->Session->write('redir', array('controller'=>$this->request->params['controller'], 'action'=>$this->request->params['action'], implode($this->request->params['pass'], '/'))); } }
Checking var session with debug($this->Session->write('redir')); , everything will look perfect until I go to the login action:
UsersController.php public function login () { if ($this->request->is ('post')){ if ($this->Auth->login()) { $redir = $this->Session->read('redir'); if (!empty($redir)) { $this->redirect ($redir); } else { $this->redirect ($this->Auth->redirect()); } } } }
Performing this application interrupt, and if I debug($redir); var i get:
array( 'controller' => 'js', 'action' => 'jquery', (int) 0 => 'plugin/jquery.validata.1.7.min'
instead
array( 'controller' => 'venue', 'action' => 'apartments', (int) 0 => '1564/venue-name' )
If I debug($redir); in any other representation of the whole site, everything works well, and I get the necessary data.
I thought of some sort of session protection procedure for the $this->Auth->login() action, but for me this is completely pointless.
How can I just redirect the user registered to the last page, which is not a login browse page?