We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon login and redirect page before

Hi Phalcon group, Do I need to login first page, if not logged in will be redirected to the page LoginAction. After a successful login, will be moved to the previous page.

Please help me



58.4k

Hi man

You have two options for this, first you use session to save path or use parameter login?url="path-want-to-redirect"

$this->response->redirect($this->request->getHTTPReferer()); it's not working

See also $this->request->getHttpReferer().

edited Mar '16

getHTTPReferer() returns the full URL (for example, "https://forum.phalcon.io/discussion/10735/phalcon-login-and-redirect-page-before" instead of "/discussion/10735/phalcon-login-and-redirect-page-before"). By default, redirect() assumes the URL is an internal link and uses the URL component to resolve it. Set the second parameter as true if you want to pass a full URL.

$this->response->redirect($this->request->getHTTPReferer(), true);

$this->response->redirect($this->request->getHTTPReferer()); it's not working

See also $this->request->getHttpReferer().

It should be noted that the HTTP Referer is provided by the browser, and isn't guaranteed. Consequently, it can't be relied on 100% to give the previous page.