Cameron
Cameron

Reputation: 28803

CakePHP: if user did not come from the same website

How would I check if the user did not come from the same website? So for example if a user types in the URL in the browser to a direct page then they would have accessed that page without coming from another page in the site.

So something like:

if(!user not from same url)
{
//do some stuff
}

Upvotes: 0

Views: 215

Answers (2)

Cameron
Cameron

Reputation: 28803

$referer = env('HTTP_REFERER');

if(empty($referer) && $this->Session->check('Auth.redirect') == false)
{
    echo 'user didn\'t come website and wasn\'t redirect from the auth component';
}

Upvotes: 0

Anh Pham
Anh Pham

Reputation: 5481

$this->referer() in controller?

Edit: Well, for your purpose, you can directly use this:

$referer = env('HTTP_REFERER');
if(empty($referer)){ echo 'jazz'; }

because $this->referer() behaves a little differently. It won't return false or null or empty string.

Upvotes: 1

Related Questions