Dirk
Dirk

Reputation: 115

CakePHP 3: Allow access only when being redirected from a specific action

Good Morning, I'm trying to allow access to an controller only if the user is redirected from an other controller.

if ($this->referer() != 
  Router::url(array(
    'controller'=>'customers', 'action'=>'register'
  ))) {
  return $this->redirect(['controller'=>'customers','action'=>'register']);
}

But the above snippet always redirects me to customers/register.

I could not find anything in CakePHP documentation, so if anyone has an idea for me?

Upvotes: 0

Views: 173

Answers (1)

code-kobold
code-kobold

Reputation: 824

$this->referer() returns an URL, e.g. http://foo.localhost/controller/action, while Router::url returns a route only, e.g. /controller/action.

Thus your condition does not match.

Upvotes: 1

Related Questions