Reputation: 255
I know HTTP_REFERER is not safe as a security measure, but I still want to know.
How can I check if the value of HTTP_REFERER contains www.someexample.com even though it may be www.someexample.com/awards/user/145??
Upvotes: 5
Views: 13551
Reputation: 219938
if( stripos($_server['HTTP_REFERER'], 'someexample.com') !== FALSE ) {
// The link is from someexample.com (might not have "www" in it)
}
Note: This'll also match http://www.andsomeexample.com
. If you want to prevent that, use parse_url
:
if( parse_url($_SERVER['HTTP_REFERER'])['host'] == 'someexample.com'){
// You're good to go...
}
Upvotes: 3
Reputation: 50976
if (false !== stripos($_SERVER['HTTP_REFERER'], "www.someexample.com")){
//do stuff
}
Upvotes: 8
Reputation: 1343
If using Apache, simply perform a preg_match on $_SERVER['HTTP_REFERER']
Upvotes: 0