helloandre
helloandre

Reputation: 10721

getting referer from auth in cakePHP

I have a link on the main page that is only accessible if they are logged in. However, if this link is clicked, I want to show a custom error message on the login page (a custom 'Message.auth').

i.e. I want (pseudo code)

if (referer == '/users/reserve'){
    Message.auth = 'Please log in to reserve tickets';
}
else {
    Message.auth = 'Please log in to access that page';
}

Where would I put this bit of code?

Upvotes: 1

Views: 1861

Answers (2)

neilcrookes
neilcrookes

Reputation: 4203

Provided you have auth flash messages being output in the login view, this should work:

// login action of users_controller.ctp
if ($this->Session->check('Auth.redirect')
 && $this->Session->read('Auth.redirect') == '/users/reserve') {
  $this->Session->write('Message.auth', 'Please log in to reserve tickets');
}

Upvotes: 1

cp3
cp3

Reputation: 2139

to get referer you can call $this->referer() to get the referring URL then pass that value to your view.

see: referer

Upvotes: 1

Related Questions