1
如何使用PHP和GD库创建与此相同的验证码?在PHP/GD库中创建自定义验证码
来源:http://www.aphrodite-agency.com/assets/captcha/captcha.php
圈中是有效的,只有字母或数字...
的index.php:
<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Demo captcha</title>
</head>
<body>
<form method="POST" action="">
<h3>Quel est ce chiffre ?</h3>
<img src="captcha.php" /><br />
<input type="text" name="captcha" style="width:70px"/><br />
<input type="submit" />
</form>
<?php
if($_POST['captcha']){
if($_POST['captcha']==$_SESSION['captcha']) echo '<h3 style="color:green">Bingo !</h3>';
else echo '<h3 style="color:red">Oups !</h3>';
}
?>
</body>
</html>
captcha.php:
<?php
session_start();
$_SESSION['captcha'] = rand(1000,9999);
$img = imagecreatetruecolor(70, 30);
$fill_color=imagecolorallocate($img,255,255,255);
imagefilledrectangle($img, 0, 0, 70, 30, $fill_color);
$text_color=imagecolorallocate($img,10,10,10);
$font = './28DaysLater.ttf';
imagettftext($img, 23, 0, 5,30, $text_color, $font, $_SESSION['captcha']);
header("Content-type: image/jpeg");
imagejpeg($img);
imagedestroy($img);
?>
第1步,停止重新发明车轮并使用类似recaptcha的东西。 –
这是否给出了任何错误或您对我们的期望? – Bram