anti spam field in form

后端 未结 2 1899
-上瘾入骨i
-上瘾入骨i 2021-01-28 18:57

i am using vtiger and recieveing alot of spam on the website contact page i am using this code

        
相关标签:
2条回答
  • 2021-01-28 19:09

    Add an extra field to the form that you do not use. Hide it with css.

    Spam bots visiting the page will fill all fields, even if they are not shown.

    If there's something in the hidden field, the whole form is spam, and you can discard the data.

    0 讨论(0)
  • 2021-01-28 19:19

    I would recommend You other antiSpam method - with token/private key.

    In HTML form You put this:

    <form action="..." method="post">
    <?php
    $publicKey = rand()%9;
    $privateKey = 0.9;
    $token = sha1( $publicKey * $privateKey + $privateKey );    
    ?>
    <input type="hidden" name="publicKey" value="<?php echo $publicKey; ?>" />
    <input type="hidden" name="token" value="<?php echo $token; ?>" />
    </form>
    


    And add also few lines of code before IF condition - for example: fragment with SQL query or send mail, just to check/validate sended token by POST method:

    <?php
    $publicKey = $_POST['publicKey'];
    $privateKey = 0.9;
    $token = sha1( $publicKey * $privateKey + $privateKey );
    
    if ( $token == $_POST['token'] ) {
    
    // do something, eg: SQL query, send mail
    
    }
    ?>
    

    AND REMEMBER! Always validate and sanitize all Your input data! :)

    0 讨论(0)
提交回复
热议问题