Tag Archives: Captcha Genarate

How to implement captcha in php?


This is the tutorial that can implement the captcha in the PHP form and verify the user which is a real user or any robot users. so just make the below files and set to your form which can attach the captcha.

Step 1)

Make php file and put the below code there.

     <img src="captcha_code.php"/>
     <input name="captcha_code" type="text" id="captcha_code" placeholder="Enter Captcha Code">

Step 2)

Make another file name “captcha_code.php”. put the below code in that file.

$random_alpha = md5(rand());
$captcha_code = substr($random_alpha, 0, 6);
$_SESSION["captcha_code"] = $captcha_code;
$target_layer = imagecreatetruecolor(70,30);
$captcha_background = imagecolorallocate($target_layer, 148, 7, 10);
$captcha_text_color = imagecolorallocate($target_layer, 255, 255, 255);
imagestring($target_layer, 8, 8, 8, $captcha_code, $captcha_text_color);
header("Content-type: image/jpeg");

Step 3)

Now visit your form it will display the captcha code in your form.