【发布时间】:2014-03-04 01:34:54
【问题描述】:
如何使用 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>
验证码.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 的东西。
-
这是否有任何错误或您对我们有什么期望?