1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Do your PHP forms get spammed? - Here's your solution:

Discussion in 'PHP' started by Notting, Nov 28, 2007.

  1. #1
    Workings:

    Basically, you have a field in your form which is hidden with CSS. If a human visitor comes along they cannot enter a value in it because it is hidden.

    When a BOT comes along they usually fill out all fields. This means the hidden field will have a value in it.

    The PHP snippet goes on your form processing page and if it finds the hidden field has been filled in it stops processing the form.

    Bingo! ~ Enjoy.

    Notting



    Put this field in your form:

    <input name="textfield6" type="text" class="hidden" size="1" />

    Put this style in your Css:


    .hidden {
    width:5px;
    visibility:hidden;
    }

    Put this statement in your PHP code (action page):


    //spam catch
    $spam = $_POST['info'];
    if ($spam != "")
    {$errors[] = "This is a spam check. If you are a genuine visitor, then this is a technical error and we apologise. Please contact us on 0870 NNN NNNN";}


    // Display any errors and exit if errors exist.

    if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

    if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

    :)


    :):)
     
    Notting, Nov 28, 2007 IP
  2. Winagain

    Winagain Well-Known Member

    Messages:
    919
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    that's an elegant solution.

    thanks for sharing.
     
    Winagain, Nov 28, 2007 IP
    Notting likes this.
  3. rcj662

    rcj662 Guest

    Messages:
    4,403
    Likes Received:
    97
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nice tip. I am sure some people can use this one.
     
    rcj662, Nov 28, 2007 IP
  4. mvl

    mvl Peon

    Messages:
    147
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Smart, thanks:p
     
    mvl, Nov 28, 2007 IP
  5. dannet

    dannet Well-Known Member

    Messages:
    863
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    153
    #5
    Good solution, I will test it, thanks!
     
    dannet, Nov 28, 2007 IP
  6. madk

    madk Peon

    Messages:
    141
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I used this solution for awhile on one of my sites. Worked great until the bot or human adapted. I think it was because I was specifically targeted. Definitely worth a shot tho and I would highly suggest adding this to a multi-tiered solution.
     
    madk, Nov 28, 2007 IP
  7. benefita

    benefita Active Member

    Messages:
    197
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #7
    I'll try it... seems good
     
    benefita, Nov 28, 2007 IP
  8. Irontree

    Irontree Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sounds clever. Watch out captcha!
     
    Irontree, Nov 28, 2007 IP
  9. Notting

    Notting Notable Member

    Messages:
    3,210
    Likes Received:
    335
    Best Answers:
    0
    Trophy Points:
    280
    #9
    How are people getting on with this? Who has implemented it?

    Notting
     
    Notting, Dec 5, 2007 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    I've been using this method since a long time now, and only ONE spam mail got through since then. (Using this method on multiple sites)

    Maybe you should not throw an error if the field was filled out though. Some bots check for errors and detect these. Just pretend like the form was submitted successfully so the bot has no chance to know what's up.
     
    nico_swd, Dec 5, 2007 IP
    Notting likes this.
  11. Notting

    Notting Notable Member

    Messages:
    3,210
    Likes Received:
    335
    Best Answers:
    0
    Trophy Points:
    280
    #11
    Thanks nico_swd, if I start getting spam this sounds like a good avenue to go down.

    Cheers
    Notting
     
    Notting, Dec 5, 2007 IP
  12. UKWebmasterForum

    UKWebmasterForum Guest

    Messages:
    477
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #12
    This is actually a very simple and very effective way of preventing bots signing up. But as someone said, the bots could adapt to it, possibly by searching HTML and CSS code...I don't know.

    Reputation added, this is a clever solution.
     
    UKWebmasterForum, Dec 5, 2007 IP
  13. lojadeluxo

    lojadeluxo Well-Known Member

    Messages:
    1,080
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #13
    good solution for this big problem...
    i´ll use
     
    lojadeluxo, Dec 5, 2007 IP
  14. Hernan

    Hernan Peon

    Messages:
    45
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Seems good, thanks for sharing :)
     
    Hernan, Dec 5, 2007 IP
  15. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #15
    woow.. great.. You deserce a green rep for this.

    I've been using captchas all this time, it's not so user friendly!
     
    selling vcc, Dec 5, 2007 IP
  16. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Nice solution, you could make it even tighter by having a hidden field that is updated with a value when the submit button is clicked. My guess is that bots don't click the submit button but just post to the forms target?

    Also check the the post is coming from your actual site by checking the $_SERVER["HTTP_REFERER"] - this catches most remote injections.
     
    Gawk, Dec 6, 2007 IP
  17. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #17
    Not really. Most bots are aware of this and automatically set the referrer (just in case).
     
    nico_swd, Dec 6, 2007 IP
  18. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Yes, you are right nico_swd, it should have said 'some remote injections' not 'most remote injections'
     
    Gawk, Dec 6, 2007 IP
  19. CJJR

    CJJR Peon

    Messages:
    177
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Thanks Notting, that's very clever, I'll try it.
     
    CJJR, Dec 8, 2007 IP
  20. jjdomainer

    jjdomainer Active Member

    Messages:
    216
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #20
    thank you Notting, I will be using this tip ;)
     
    jjdomainer, Dec 8, 2007 IP