Validate Referrer
8
Validate Referre
<?php
// Validates a referer
function ValidateReferer($strDomain)
{
// Make domains
$strDomain = str_replace("www.", "", strDomain);
// Check
if (strstr($_SERVER["HTTP_REFERER"], $strDomain))
{
return true;
}
return false;
}
?>
// Validates a referer
function ValidateReferer($strDomain)
{
// Make domains
$strDomain = str_replace("www.", "", strDomain);
// Check
if (strstr($_SERVER["HTTP_REFERER"], $strDomain))
{
return true;
}
return false;
}
?>
Comments
Voting
Votes Up
ASmith
bertheymans
ColdKeyboard
dannyboy
i_kenneth
marius_wiz
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
mattrmiller
Pio
RatNuShock
SecondV
shachi
sundaramkumar
wiz1705






=================
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!