Skip Navigation LinksHome > Categories > Code from a Category

Protecting the site from spammers using PHP.



User Name: serfcompany
Name: Serf
Contact Me: www.datawebcoder.com
Home Page: www.datawebcoder.com
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 219
Add Date: 03/17/2012
Currently, many good sites suffer from huge flow of ads or just spam that is not bona fide users of the Internet trying to locate wherever possible: in guest books, forums, directories, and wherever possible to leave a couple of lines of text.

The main method of combating the phenomenon of this kind of spam is to create all sorts of checks on humanity, that is, determine who enters the data into a form that a person or program.
These checks include:


* Please enter the number into a text box or word from the picture
* Enter the answer to a riddle or a question
* Press one of a few buttons (input type="button">)
* Choose from a number of correct answers (input type="radio">)
* To select multiple answers (input type="checkbox">)


Despite such a significant list of methods to combat spam, usually applied only to the first point, ie use images with text or numbers.


Algorithm for reconciliation in this case is carried out in several ways:


# The form has one or more hidden elements () containing values ??and the field for data entry.
# Randomly generated value is stored in a database and a short period of life, the coincidence with the value of the textbox located. in the form of this entry is deleted.
# Use of Cookies, that is, maintaining the correct answer from the user (not very convenient and does not always work).
# As a confirmation code uses mixed numbers of the current date.
# The previous version, but diluted with Latin letters.
# Boundless imagination of developers ...


We will consider the easiest way to deal with spammers, ie numeric code printed on the image, consisting of mixed current date.
This confirmation code will be valid for less than ten minutes from the time of its generation.
It will be done on the image, each time the code will be different in different parts of pictures, from different angles on different backgrounds and different fonts is written.
First let's define what we will be using out of date, I propose to use the current: the day of the week, month, day, hour, minute (first number) and the day of the year.
In my opinion, this is an impregnable defense for simple programs, registrars or their authors as determine exactly what values ??of the dates are used to generate a confirmation code is virtually impossible.
But if you and it's not enough, you can multiply or add all the values??, or for each day of the week to use its algorithm, it all depends on your imagination.


And so, let us write our php-code, and then I was too much absorbed in the theoretical part of the question. <
Create a new php-file and to start a write in it a function that will "invent" a confirmation code from the current date, it will look like this:



Now that we have already prepared a function to generate a digital code confirmation, you can write a function to generate the code in the image taken from a file and then output the resulting image with a confirmation code to the browser.


In order for everything to work at the beginning of php-script writing:



,and at the end



Then create a folder in the directory my_codegen, which is php-script - image generator with a confirmation code, and create and codegen.png codegen0.png in Photoshope or another graphics program, copy back TrueType fonts with names and Kiloton.ttf 04B_24__.TTF .
All images on this generator is completed.


Now we need a function to validate user input, it will be implemented on the same principle as generate_code, it should be placed in a separate php-script, which will be to verify the entered data:



In the same file at the end add the function generate_code ()


At the conclusion of an exemplary implementation of the scheme:



Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.