carlgcode
carlgcode

Reputation: 255

how can I check if the HTTP_REFERER contains a string, but not exact match?

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

Answers (4)

Joseph Silber
Joseph Silber

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

Fivell
Fivell

Reputation: 11929

echo parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);

Upvotes: 1

genesis
genesis

Reputation: 50976

if (false !== stripos($_SERVER['HTTP_REFERER'], "www.someexample.com")){
   //do stuff
}

Upvotes: 8

EddieBytes
EddieBytes

Reputation: 1343

If using Apache, simply perform a preg_match on $_SERVER['HTTP_REFERER']

Upvotes: 0

Related Questions