復制代碼 代碼如下:
 
<? 
require_once ('classes/Akismet.class.php'); 
class MySpamProtection { 
// variables 
var $sMyAkismetKey; 
var $sWebsiteUrl; 
var $sAuthName; 
var $sAuthEml; 
var $sAuthUrl; 
var $oAkismet; 
// constructor 
public function MySpamProtection() { 
// set necessary values for variables 
$this->sMyAkismetKey = '__YOUR_AKISMET_KEY__'; 
$this->sWebsiteUrl = '__YOUR_WEBSITE_URL__'; 
$this->sAuthName = '__YOUR_NAME__'; 
$this->sAuthEml = ''; 
$this->sAuthUrl = ''; 
// Akismet initialization 
$this->oAkismet = new Akismet($this->sWebsiteUrl ,$this->sMyAkismetKey); 
$this->oAkismet->setCommentAuthor($this->sAuthName); 
$this->oAkismet->setCommentAuthorEmail($this->sAuthEml); 
$this->oAkismet->setCommentAuthorURL($this->sAuthUrl); 
} 
public function isSpam($s) { 
if (! $this->oAkismet) return false; 
$this->oAkismet->setCommentContent($s); 
return $this->oAkismet->isCommentSpam(); 
} 
} 
echo <<<EOF 
<style type="text/css"> 
form div { 
margin:10px; 
} 
form label { 
width:90px; 
float:left; 
display:block; 
} 
</style> 
<form action="" method="post"> 
<div><label for="author">Author</label><input type="text" value="" /></div> 
<div><label for="comment">Comment</label><textarea cols="20" rows="4"></textarea></div> 
<div><input type="submit" value="Send" /></div> 
</form> 
EOF; 
if ($_POST) { 
// draw debug information 
echo '<pre>'; 
print_r($_POST); 
echo '</pre>'; 
// obtain sent info 
$sPostAuthor = $_POST['author']; 
$sCommentComment = $_POST['comment']; 
// check for spam 
$oMySpamProtection = new MySpamProtection(); 
$sAuthorCheck = ($oMySpamProtection->isSpam($sPostAuthor)) ? ' "Author" marked as Spam' : '"Author" not marked as Spam'; 
$sCommentCheck = ($oMySpamProtection->isSpam($sCommentComment)) ? ' "Comment" marked as Spam' : '"Comment" not marked as Spam'; 
echo $sAuthorCheck . '<br />' . $sCommentCheck; 
} 
?> 
新聞熱點
疑難解答