.: Step By Step: Add Image Validation To Your Website Form

By:David Picella

Category:Home / Computers

Copyright 2006 David Picella



If you are a do-it-yourself programmer and you want to know how to add image validation to a form on your web site then this is the article for you. While there are many ways to do this, if you follow these steps, you will learn the easiest way to get the job done. Once you have mastered the example here, you will have all the concepts and experience you need to incorporate the final product into your form on your website.



We will need two files. The first file will create the validation image and incorporate the image in a validation form. Here is the step-by-step code for the first file: verify.php



---BEGINNING OF FILE: VERIFY.PHP---



< ?php



// Create an image where width=200 pixels and height=40 pixels



$val_img = imagecreate(200, 40);



// Allocate 2 colors to the image



$white = imagecolorallocate($val_img, 255, 255, 255);



$black = imagecolorallocate($val_img, 0, 0, 0);



// Create a seed to generate a random number



srand((double)microtime()*1000000);



// Run the random number seed through the MD5 function



$seed_string = md5(rand(0,9999));



// Chop the random string down to 5 characters



// This is the validation code we will use



$val_string = substr($seed_string, 17, 5);



// Set the background of the image to black



imagefill($val_img, 0, 0, $black);



// Print the validation code on the image in white



imagestring($val_img, 4, 96, 19, $val_string, $white);



// Write the image file to the current directory



imagejpeg($val_img, "verify.jpg");



imagedestroy($val_img);



? >



< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"



"http://www.w3.org/TR/html4/loose.dtd" >



< html >



< head >



< meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >



< title >Image Verification< /title >



< /head >



< body >



< img src="verify.jpg" height="40" width="200" alt="validation image" / >



< br / >< br / >Type in the validation code from the image. (case sensitive)



< form action="validateform.php" method="post" >



< input name="random" type="text" value="" >



< input type="submit" >



< !-- The validation code will be posted from a hidden form element -- >



< input name="validation" type="hidden" value="< ?php echo $val_string ? >" >



< /form >



< /body >



< /html >



---END OF FILE: VERIFY.PHP---



Now we will create a file that will perform the validation using the POST method:



---BEGINNING OF FILE: VALIDATEFORM.PHP---



< ?php



if ($_POST['validation'] == trim($_POST['random'])){



echo "You are validated";



}



else{



echo "Please go back and get validated.";



}



? >



---END OF FILE: VALIDATEFORM.PHP---



IMPORTANT NOTE: Because many free article websites don’t support HTML in the body of the article the files above won’t work unless you eliminate the space after < and before >. Just do a find and replace all.



That is really all there is to it. You probably noticed that I also went to the trouble of including the DOCTYPE and charset lines in this simple example. I did this as a little reminder to make sure that all of your pages on your website are W3C compliant. One of the biggest mistakes that many webmasters make is to neglect W3C compliance on their web pages. If your web pages are not W3C compliant you will get low search engine rankings. Even worse, if you are advertising, your ads may not be as relevant as they should be! In my other article, I explain W3C compliance and the most common mistakes.

Digg del.icio.us Blink Stumble Spurl Reddit Netscape Furl

Article keywords: form html, forms html, html, html image, image php, javascript form validation, method post, php, php script, validation form, verification form, spam, anti spam, filter spam

Article Source: http://www.articles32.com

Original article and source code for download are available at picella.com --The author, David Picella, is a PhD Student at the University of Wisconsin Milwaukee. In addition to his technical articles on technology and Internet subjects, he has written other articles on health care topics in women's health and reproductive care.





.: New Computers Articles

1). Is Spyware Slowing Your Computer Down To A Crawl?
Everyday more and more computers are becoming infected with Spyware and Adware (advertising tracking).

2). Writers and Ergonomics
This article talks about the need to pay attention to your body if you sit in a chair at a computer for long hours and talks about some of the ergonomic solutions to this problem

3). Anti Adware and Spyware Programs
Adware is any software application software which makes banners appear the whole time it is in function. Also, the adware program can install components that will transmit information about the user and its behavior and this work on his PC.

4). Why HP Toner Cartridges Are The Best
Many factors determine a quality toner cartridge. Find out why HP toner cartridges always seem to come out on top.

5). Microsoft Dynamics GP Customization Tools Evolution, Overview For Consultant
This small article is targeted to Microsoft Dynamics GP audience. Recent Microsoft marketing move from Microsoft Business Solutions to Dynamics means Project Green wave 1 progress.

6). Data Recovery Software: At Your Rescue
Computers are an integral part of our lives. They are used at every juncture, and of course play a major role in businesses. In fact, the smooth working of small, medium, big and very big enterprises depend heavily on the computer. But they arent perfect, and it would be unfair to consider them as perfect.

7). Consumer Beware... Identity Theft Tools & Techniques
Identity theft is very quickly becoming the crime of choice for thousands of criminals worldwide. With online Internet access to just about any kind of database you want becoming easier and easier to acquire, the crime of Identity Theft is becoming so easy, a child could do it, if they are even mildly adept at using a computer.


.: Top Computers Articles

1). Httpwww.google.com, httpgroups.yahoo.com, Invalid URL, Why?
So you have heard of Google or Yahoo, fired up the trusty Internet Explorer and typed one of the following phrase's in the search bar, httpwww.google.com, httpgroups.yahoo.com, httpyahoo.com, or perhaps wwwgmail.com, hit search, "--" Eh, Nothing, WHY? You are not alone, over 3,000,000 people a year type in httpwww.google.com, over 2,000,000 type in httpgroups.

2). Understanding Your PC's CPU Clock Speed And Front Side Bus
Copyright 2006 Otis Cooper Have a computer in your home that is put to use often? Why not take the time to fully understand the terms, the components,and software used to make it work. To understand your PC is not hard and you'll be rewarded greatly. How you ask? By upgrading your own system as well as repairing those of your friends while earning extra cash in the process.

3). Holiday Myspace Backgrounds For Your Myspace Profile
Myspace is now one of the top five most-visited websites in the world. Indeed, it has taken the Internet world by storm. At last count, they had more than 30 million users from around the globe. Amazing, isn't it? This article is for regular myspace users. A lot of changes can be made in your myspace profile to make it look more colorful, cheerful and appealing.

4). Step By Step: Add Image Validation To Your Website Form
Copyright 2006 David Picella If you are a do-it-yourself programmer and you want to know how to add image validation to a form on your web site then this is the article for you. While there are many ways to do this, if you follow these steps, you will learn the easiest way to get the job done. Once you have mastered the example here, you will have all the concepts and experience you need to incorporate the final product into your form on your website.

5). The danger behind peer-to-peer file sharing
File sharing is very common nowadays. You can get a P2P (peer-to-peer) program for free, and soon start sharing stuff like music, videos and programs. We use these applications freely and most of us don’t know the risks involved when using them. Questionable reliability of files – Once we get our hands on a P2P program, we download everything we want like crazy.

6). RAM and Latency... what you need to know
RAM latency is one of the most overlooked methods of optimizing your computer. Find out exactly how you can tweak your memory timings in order to make your system run quicker.

7). Verizon DSL - It's Cheaper Than You Think
Verizon DSL is a digital subscriber link (DSL) internet service provided by Verizon communications. Internet can be accessed in many ways like cable, ISDN, dial-up, optical fiber, power line internet, satellite, wi-fi, DSL etc. The advantage of DSL is that the voice telephone and fax can be used simultaneously with the internet connection. DSL technology takes advantage of the fact that on the telephone line, voice occupies a very small bandwidth and a large bandwidth is unused.


Page loaded in 0.337 seconds.