How to implement captcha in php?

How to implement captcha in php?

How to implement captcha in php?

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

Step 1)

Make a PHP file and put the below code there.

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

Step 2)

Make another file named "captcha_code.php." Put the below code in that file.

<?php
session_start();
$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);
imagefill($target_layer,0,0,$captcha_background);
$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");
imagejpeg($target_layer);
?>

Step 3)

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

0 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *