generete.php
this page have to make a captcha picture to user but it did not work for me
<?php
session_start();
header('Content-Type: image/jpeg');
$text=$_SESSION['secure'];
$font_size=30;
$image_width=200;
$image_height=40;
/*use width and height to make image
$image=imagecreate($image_width,$image_height);
imagecolorallocate($image,255,255,255);
$text_color=imagecolorallocate($image,0,0,0);
/* add a few lines to hard to reading*/
for($x=1;$x<=20;$x++){
$x1=rand(1,100);
$x2=rand(1,100);
$y1=rand(1,100);
$y2=rand(1,100);
imageline($image,$x1,$x2,$y1,$y2,$text_color);
}
imagettftext($image,$font_size,0,15,30,$text_color,'B Elm.ttf',$text);
imagejpeg($image);
?>
index.php this page check if user enter correct value that shows in picture or not, if is correct show the 'A match.'
<?php
session_start();
if(!isset($_POST['secure'])){
$_SESSION['secure']=rand(1000,9999);
}else {
if($_SESSION['secure']==$_POST['secure']){
echo'A match.';
} else{
/*if user enter wrong characters, can refresh and get new code.*/
echo'incorrect , not match.';
$_SESSION['secure']=rand(1000,9999);
}
}
?>
<img src="generate.php" /> <br>
<form action="" method="POST">
type the value you see: <input name="secure" type="text" size="4" maxlength="4">
<input name="Submit" type="submit" value="Submit">
</form>