<%
if(!$spam){
// send your email
}
function check_referer($referers)
{
// If there are any referrers in the list ...
if (count($referers))
{
$found = false;
// Use the browsers referrer header.
$temp = explode("/",getenv("HTTP_REFERER"));
$referer = $temp[2];
if ($referer=="")
{
$referer = $_SERVER['HTTP_REFERER'];
list($remove,$stuff)=split('//',$referer,2);
list($home,$stuff)=split('/',$stuff,2);
$referer = $home;
}
// Check agains list.
for ($x=0; $x < count($referers); $x++)
{
if (eregi ($referers[$x], $referer))
{
$found = true;
}
}
// Refererer is blank.
if ($referer =="")
$found = false;
if (!$found)
{
// You might alter this to print some sort of error of your own.
print_error("You are coming from an unauthorized domain.");
error_log("[FormMail.php] Illegal Referer. (".getenv("HTTP_REFERER").")", 0);
}
return $found;
}
else
{
return true;
}
}
So, then we check it in the code and bail out if it's an invalid referer, thus.
if (!check_referer($referers))
{
/// Bang, wallop and exit.
}
%>