Featured Posts

Getting into Java... I'm starting to make my first Java applications with the aim of being able to program cell phone API and other handheld technologies. I see this as a huge market in years to come and can wait to get my...

Read more

Teaching Intro to Flash at Tunxis Again Looks like I'll be teaching at Tunxis again this semester. Can't wait to get started again as I have a lot of fun the last time we did this. The class is going to be restructured slightly to showcase the...

Read more

The difference between classic and motion tweens in... Here it is: If you're used to doing things "the cs3 way" then you can continue to do so with the classic tween tool. It works the same way as you remember, using key frames as normal, but you cannot...

Read more

PHP: If (equal to AND not equal) - eliminate form spam... Just learned a great function of PHP thats already made my forms a lot better. A while back I wrote an article about eliminating form spam without captchas by using css to hide a text input box for bots...

Read more

Drop Downs, Fly Outs, and Accordion Site Navigation: This last week I was in a meeting discussing a client site. It was a typical business meeting that was going into overtime on a Friday afternoon, and then things turned for the worst... someone suggested...

Read more

twitter

Breaking News

  •  

PHP: If (equal to AND not equal) – eliminate form spam without using a captcha

Category : Featured, Slick Code, Technology

Just learned a great function of PHP thats already made my forms a lot better. A while back I wrote an article about eliminating form spam without captchas by using css to hide a text input box for bots to fill in. By giving the input box a legit sounding name like “email” the bots fall for the trap and the php handler discards their form entry results.

The only problem was that I still got blank entries every now and again from people using their back button, or search engine spiders. You could also trick the validation script by surfing with java turned off . And while I still dont know exactly which one of the above was the cause I have an ultimate solution.

The equal to and not equal to feature in PHP.

Instead of:

if ($test == "") {
mail($mailto, $mailsubj, $mailbody, $mailhead);
}

We use:

if ($test == "" && $email != "") {
mail($mailto, $mailsubj, $mailbody, $mailhead);
}

This little change not only checks to see that there is nothing in the hidden field but also checks to see that there IS something in the email field. As the email is required this is nothing new, but will dump all the blank entries I’ve been getting.

FYI:
&& = = and
!= = not equal to

Post a comment