【发布时间】:2014-07-29 16:46:01
【问题描述】:
我正在尝试在我的页面上创建自己的验证码以进行登录,但是此 php 代码不会在我的网页上显示我的验证码图像。所以任何建议都会很好。 这是我的 captcha.php
<?php
session_start();
// generate random number and store in session
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
//generate image
$im = imagecreatetruecolor(100, 38);
//colors:
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 35, $black);
// ------------- your fontname -------------
// example font http://www.webpagepublicity.com/free-fonts/a/Anklepants.ttf
$font = 'Anklepants.ttf';
//draw text:
imagettftext($im, 35, 0, 22, 24, $grey, $font, $randomnr);
imagettftext($im, 35, 0, 15, 26, $white, $font, $randomnr);
// prevent client side caching
header("Expires: Wed, 1 Jan 2015 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revаlidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//send image to browser
header ("Content-type: image/PNG");
imagegif($im);
imagedestroy($im);
?>
我的 html 代码显示验证码图像是试用代码。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>books Collection</title>
</head>
<body>
<div >
<form>
<img src="captcha.php" /></br>
<img src="captcha.png" /></br>
<input type="text" name="answer" placeholder="Enter captcha here" />
<input type="submit" value="CHECK" />
</form>
</div>
</body>
</html>
【问题讨论】:
-
您的问题在于您的
imagettftext()函数。看看这个Example
标签: php html css caching fonts