EGP
EGP

Reputation: 397

How to check referral url and re-direct based on that?

I need to check referral url and if it's generated from Facebook redirect the user to a different webpage. How do I do that?

Upvotes: 1

Views: 901

Answers (2)

Marc B
Marc B

Reputation: 360572

if (stripos(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST), 'facebook') !== FALSE) {
   header('Location: differentwebpage.html');
}

Upvotes: 1

Brad
Brad

Reputation: 163272

Take a look in $_SERVER['HTTP_REFERER'].

You can then use parse_url() to get the hostname, and compare the domain to a list of known Facebook domains.

Beware, the referer isn't required, and isn't always set. So, don't use it as any kind of security.

Upvotes: 3

Related Questions