I need to check referral url and if it's generated from Faceboo开发者_运维知识库k redirect the user to a different webpage. How do I do that?
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.
if (stripos(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST), 'facebook') !== FALSE) {
header('Location: differentwebpage.html');
}
精彩评论