Captcha

Started on the old forum in February 2009 · view the original in the archive · old links redirect here

1 reply · 591 views · started 17 years ago · 1 min read

2 participants
tkrocks Junior · 39 posts #1

CODE

<?php //This is php_captcha.php // Make a simple jpg graphic (100x35 pixels or so) and save to the same space as this file session_start(); $RandomStr = md5(microtime());// md5 to generate the random string $ResultStr = substr($RandomStr,0,5);//trim 5 digit $NewImage =imagecreatefromjpeg("captcha.jpg");//image create by existing image and as background $LineColor = imagecolorallocate($NewImage,233,239,239);//line color $TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white imageline($NewImage,1,10,200,30,$LineColor);//create line 1 on image imageline($NewImage,1,50,60,0,$LineColor);//create line 2 on image imagestring($NewImage, 5, 20, 5, $ResultStr, $TextColor);// Draw a random string horizontally $_SESSION['key'] = $ResultStr;// carry the data through session header("Content-type: image/jpeg");// output the image imagejpeg($NewImage);//Output image to browser ?>

Save this file to your webspace somewhere with a small jpg image of like 100 by 35 pixels or so (any color). Then within your forms where you want the user tested (to keep out automated bots and mass mailers), you place this additional code.

werever u want users to submit the code <input name="captcha" type="text"> //Users will enter the code here External image (may be gone) //This will produce the captcha image
After submitting the form, your PHP will verify the key they entered against the one saved in the user's SESSION tag.

......................in the next page or u wan c if the text entered is right o wrong

$key=substr($_SESSION['key'],0,5); $captcha = $_POST['captcha'];

if ($key!=$captcha) { // Error! The key did not match } else { // Success! Verification complete }

NOTE: U CN FORM UR OWN IMAGE .....AS CAPTCHA.JPG

I WAS BORNED INTELLIGENT BUT EDUCATION RUINED ME...!!!

djlee Developer · 224 posts #2

i would strongly recommend the use of recaptcha .. i have and do like my own captcha mods however captchas are a security feature not a style feature... therefore go with something tried and tested by millions of websites and by billions of users. Plus each time you use it you help by digitizing paper based media

sure your own captcha mod may be fine.. but the way i see it, if its a security mod to a site then use the most secure method of implementation

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close