by Bhumi // Nov 17,2012 // 1 comment.
If you are looking for simple and easiest CAPTCHA code using PHP. In this tutorial I am going to explain how to implement own CAPTCHA in PHP with use of some existing image functions in PHP for creating an image.
A CAPTCHA is a random string which is basically used to protect website from spam.Here I am going to show you the one of the easiest CAPTCHA code and you can easily add into your site. Here I have generate a character with using some string functions and loop.
$charlist = "ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#*&^$@%><";
$cnt = strlen($charlist) - 1;
$char = "";
while(strlen($char) < 6)
$char .= $charlist[rand(0,$cnt)];
Next,place below code and here I have defined
png image to create a CAPTCHA but you can use jpeg,bmp and gif also. In header, ‘
Content-Length‘ will be png if you are going to use imagepng and jpeg, if imagejpeg.In imagecreate function, you need to pass own width and height for image.
$imghandle = imagecreate(width,height) or die('Cannot initialize new GD image stream');
/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($imghandle,0,0,0);
$text_color = imagecolorallocate($imghandle,255,255,255);
$noise_color = imagecolorallocate($imghandle, 100, 120, 180);
/* output captcha image to browser */
imagedestroy($imghandle);//destroy the image instance
Now, When submit CAPTCHA code, have to validate captcha text entry and without validation, CAPTCHA is useless. so to validate CAPTCHA, first we take CAPTCHA code into SESSION variable and compare it with the user entered text passed as POST data.
$_SESSION['captcha'] = $char;
That’s it.What do you think is this easiest technique I’ve mentioned above? Why or why not? Share your thoughts and questions in the comments.
Method Chaining is the new feature of object-oriented approach introduced in PHP5.Today I am going to explain how to use method chaining in PHP5. Method READ MORE
Today i am going to explain about how to create zoho leads from php. Zoho provide online lead management system.Zoho leads take details of company, READ MORE
Here i am going to explain new article about how to call webservice in wordpress. Webservices are useful to retrieve your contents ftom PHP to READ MORE
After a long long time i get time to write article and i am curious to write but didn’t get time. So, Today I am READ MORE
Posted on Mar 2,2012
Posted on Dec 1,2011
Posted on Nov 26,2011
Posted on Jan 18,2013
Posted on Dec 12,2011
Be a Contributor at CreativeDev.Write an article or tutorial to the community and share some of your knowledge!