Check user is human with no captcha | |
|
Many users are put off from adding captcha type programs to their code, either because of the complexities of it or because the PHP installed on their server does not have the image manipulation libraries needed to run it. Here is a simple and easy way from PHP to check that a user is human without having to go through the complexities of Captcha - this is very secure thanks to the miracles of MD5 (a non-reversible hashing algorithm) which unlike GD or Imagemagick is part of every PHP installation. Here is the basic code: PHP code to check a user is humanHere is how the code to stop those pesky bots works. I will show you how to add this into your application (whether its zend encoded black box code or something you control) in a moment. Function areyouhuman builds a simple arithmetical question, adding or subtracting a random number between 1 and 190 from/to a random number between 200 and 10200. It then adds a magic number to the expected answer and stores a hidden variable in the form with md5 encoding. This special encryption cannot be reversed (well it can if you have 21 days and a network of playstation 3's working on it) but will always be the same for any given input string. This means that the bot cannot simply pluck and answer from a hidden form field and return it. Above we have set the value $hum to the HTML that is returned by the areyouhuman routine. Here what the output from $hum looks like:
Function checkhum gets the values back from POST that we are interested in - just the answer($ansin) and the expected md5 if its correct ($hans) it adds the magic number to the answer and MD5 encodes it. Now if the answer is the one we are expecting then both md5's will be the same. If they are not we kill the script and stop the bot stone dead (a human can just press the back button and try again!). Please note this is not 100% secure since a programmmer could grab the maths off the page, work out the answer and send the right one, however nobody is doing this yet. A more secure way would be to use a set of images of numbers and the +/- signs - just remember not to number them 1.jpg 2.jpg etc! Now how to use the code. If its a form/script you encode then its easy.
How to use the Captcha Replacement/alternative in your codeIf we assume you have saved the above code as checkhum-inc.php....
| |