我正在尝试创建一个验证码,其中包含一个非常容易计算的总和。但是当我尝试添加 + 时,它变成了一个空白框。
问题 2 和 3
Q2:帽子头的东西真的需要和有用吗?
Q3 : $font = dirName( FILE ).'/font/karate/Karate.ttf'; 有人可以解释一下FILE的作用吗?
这是我的代码:
<?php
ob_start();
session_start();
$randomnr = rand(1, 5);
$randomnr2 = rand(1, 5);
$plus = '+';
$randanswer = $randomnr + $randomnr2;
$_SESSION['randomnr2'] = md5($randanswer);
$im = imagecreatetruecolor(80, 20);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 150, 150, 150);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 80, 25, $black);
$font = dirName(__FILE__).'/font/karate/Karate.ttf'; //wat is dit?
imagettftext($im, 15 , 7, 15, 19, $grey, $font, $randomnr);
imagettftext($im, 15 , 4 , 30, 19, $grey, $font , $plus); *PROBLEM*
imagettftext($im, 15 , 10, 50, 19, $white, $font, $randomnr2);
//prevent caching on client side:
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header ("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
ob_end_flush;
?>
示例: http: //nightcore.nl/captcha/captcha.php
如果您看到我绝对不会做的事情,请告诉我并告诉我什么更好用!