2012-03-27 8 views
1

私は友人のフォームへの送信を作成し、それをスパムに使用させたくありません。私のフォームからのスパムの防止

私は、Webを検索しましたし、

http://www.nyphp.org/phundamentals/8_Preventing-Email-Header-Injection http://www.nyphp.org/phundamentals/6_Spoofed-Form-Submissionsこれらのソースが有用であることが分かっ

は十分に良い以下のコードですか?

  • それはフォームが


function nospam($name) 
    { 
     return(str_replace(array("\r", "\n", "%OA", "%oa", "%OD", "%od", 
     "Content-Type:","BCC:","bcc:", "CC:","cc:"), "", $name)); 
    } 

    //the form posts to itself 
if(isset($_POST['submit'])){ 
    if($_POST['secret'] == $_SESSION['secret']){ 

     $_POST['email'] = nospam($_POST['email']); 
     $_POST['sendername'] = nospam($_POST['sendername']); 
     $_POST['link'] = nospam($_POST['link']); 
     $_POST['message'] = nospam($_POST['message']); 
     $_POST['senderemail'] = nospam($_POST['senderemail']); 


     $to = $_POST['email']; 
     $subject = $_POST['sendername'] . " has sent you this link."; 
     $message = "Hi " . $_POST['name'] . ",\n\n"; 
     $message .= "The following link was sent to you by " . $_POST['sendername'] . ".\n\n"; 
     $message .= $_POST['link'] . "\n\n"; 
     $message .= $_POST['message'] . "\n\n"; 
     $from = $_POST['senderemail']; 
     $headers = "From:" . $from; 
     mail($to,$subject,$message,$headers); 
     echo "Mail Sent."; 
    } 
    exit; 
}else{ 
    //set the secret variable when the page opens - only email if it exists 
    $secret = md5(uniqid(rand(), true)); 
    $_SESSION['secret'] = $secret; 
?> 

<!--html form code here --> 

<?php } ?> 
+0

あなたはCAPTCHAを使用することができますし、例えば毎分1に提出の数を制限する必要があります。 – Songo

答えて

1
を詐称することができないように、それはセッション変数を使用するすべての新しい行を削除し、新しいメッセージが
  • 追加することがカントので、文字を返します

    フォームの下部にあるreCaptchaを使用すると、このような事態を防ぐことができます。

    http://vidiame.com/php/how-to-implement-recaptcha-with-your-php-project

  • 関連する問題