Forum Moderators: coopster

Message Too Old, No Replies

Use PHP to display test as an image

Like what is used for form validation

         

chriswragg

5:07 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



I keep stumbling over websites that use
"Please enter the word you see below"
to prevent automated form submition.
The image below is simply a few characters in a strange font, but how is this done? I know google have started doing this on their add url page ( [google.com...] ) but the image is actually a link to a script with eg. id=s4e3a9b1p0 after the script url. So how do they do it? And further more, how does the form know what the actual image says?
Any help would be appreciated

Chris

bluedalmatian

6:01 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



First of all the actual sequence of characters is randomlty generated and stored temporarily, either in a database or session where it can be associated with that particular users requests.

The image itself is then generated on the fly by using PHP's image creation functions

The page & image is sent to the user and when the form is submitted, the server checks the value entered with the value it stored previosly.

Generating the random characters and storing them is pretty simple but if you've not used it before you'll need to spend some time becoming familiar with PHPs image routines. You'll ideally need a book on it to get started & the best explaination so far I've seen is Chapter 16 of Beginning PHP 4, Wrox. or Programming PHP, O'Reilly.