Here is an update, which does some extra work against automated browsers, and thus has become pretty safe and easy to update.
PHP Code:
<?php
$MyDieMessage = 'Spam filter: Please send your message through the appropriate message form.';
// Make sure the form was sent from a browser
if(!$_SERVER['HTTP_USER_AGENT'])
{
die($MyDieMessage);
}
// Make sure the form was POSTed
if(!$_SERVER['REQUEST_METHOD'] == 'POST')
{
die($MyDieMessage);
}
// Allow only the sendmessage script
$MyReferrer = strtolower($_SERVER['HTTP_REFERER']);
$MyURL = strtolower($vbulletin->options['bburl'] . '/' . $vbulletin->options['contactuslink']);
if($MyReferrer != $MyURL)
{
die($MyDieMessage);
}
// Filter header injections
$MyHeaders = array(
"Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"bcc:",
"cc:"
);
// Loop through each POST item and check for the headers
foreach($_POST as $MyKey => $MyPostItem)
{
$MyTempItem = strtolower($MyPostItem);
foreach($MyHeaders as $MyHeader)
{
if(strpos($MyTempItem, strtolower($MyHeader)) !== FALSE)
{
die($MyDieMessage);
}
}
}
// Check for '9c53d2119880d95e96e1a71e3a6c8340' in the message body.
// This string is found in automated browsers (all yet) at the bottom.
// For completeness we parse all post variables for this string.
// Prepared for more recognition strings.
$MyStrings = array(
'9c53d2119880d95e96e1a71e3a6c8340',
'dc64615b0a1e1bd3cb2689bf82248b5c' // 2006-06-27
);
// Loop through each POST item and check for the headers
foreach($_POST as $MyKey => $MyPostItem)
{
$MyTempItem = strtolower($MyPostItem);
foreach($MyStrings as $MyString)
{
if(strpos($MyTempItem, strtolower($MyString)) !== FALSE)
{
die($MyDieMessage);
}
}
}
// Cleanup
unset($MyDieMessage, $MyReferrer, $MyURL, $MyHeaders, $MyKey, $MyPostItem, $MyTempItem, $MyHeader, $MyStrings, $MyString);
?>