View Full Version : Resolved referer array

10-06-2012, 07:13 PM
Question, im trying to grab just the root of HTTP_REFERER.

The below will work but sometimes RERERER is like this


And of course in that case the key exist will be false. So whats the best way to limit REFERER to just root.


$ok_array = array('http://www.mysite.com', 'www.mysitel.com', 'mysite.com');

if (array_key_exists($ref, $ok))
//do something

I do understand that REFERER could be blank for non referrers but that will be fine, i am trying to hardcode just my site as permitted, the rest can do what they want.

i guess i could use SERVER_NAME right


10-06-2012, 08:23 PM
No, server name will be your server.
You want to use parse_url():

if (!empty($ref))
$domain = parse_url($ref, PHP_URL_DOMAIN);
in_array($domain, $ok_array))
// its in the array

so with your example, that would create $domain with the value of "www.mysite.com"