* There's a possible bug in your code. Imagine someone, who wants to check if referer is from domain awww.com. Your str_replace() will replace "www" in $strDomain, leaving $strDomain to be "a.com" which is not correct.
* Why should you use strstr() if you want to check if one string is contained in another? You should use strpos() instead.
* Why write if ($condition) return true; else return false;
if you can simply just return ($condition)?!
* Your function doesn't really work as expected: // $_SERVER['HTTP_REFERER'] = 'www.yourdomain.com.myowndomain.com';
if (ValidateReferer('yourdomain.com')) { echo 'Validated!'; }
Why not explode the referring domain by the dot sign? then check the array for www.
i.e. $str_referring_domain = $_SERVER['HTTP_REFERRER'];
$array_domain_parts = explode(".", $str_referring_domain); foreach($array_domain_parts as $part) { if(strtolower($part) == "www") { //Whatever you're going do do here } }
______________________________________________________ Yogurt? I hate yogurt! Even with strawberries!
=================
Matthew R. Miller
http://bluecreststudios.com
http://www.codeandcoffee.com
$strDomain = str_replace("www.", "", strDomain);
You're missing a dollar ($) on strDomain.
=================
Matthew R. Miller
http://bluecreststudios.com
http://www.codeandcoffee.com
"www" in $strDomain, leaving $strDomain to be "a.com" which is not correct.
* Why should you use strstr() if you want to check if one string is contained in another? You should use strpos() instead.
* Why write
if ($condition)
return true;
else
return false;
if you can simply just return ($condition)?!
* Your function doesn't really work as expected:
// $_SERVER['HTTP_REFERER'] = 'www.yourdomain.com.myowndomain.com';
if (ValidateReferer('yourdomain.com')) {
echo 'Validated!';
}
Output:
Validated!
i.e.
$str_referring_domain = $_SERVER['HTTP_REFERRER'];
$array_domain_parts = explode(".", $str_referring_domain);
foreach($array_domain_parts as $part)
{
if(strtolower($part) == "www")
{
//Whatever you're going do do here
}
}
______________________________________________________
Yogurt? I hate yogurt! Even with strawberries!