PHP 验证码 Imagettftext 不工作
在实现一个验证码脚本时遇到了困难。对 PHP 不太熟悉,所以任何帮助都会很棒。
问题:验证码图像未显示在实时服务器上,但显示在我的本地服务器上。
验证文件:
<?php
header('Content-type: image/jpeg');
$width = 90;
$height = 30;
$dir = getcwd().'/fonts/';
$black = imagecolorallocate($my_image, 0, 0, 0);
$angle = rand(0,3);
imagefilledrectangle($image,0,0,399,99,$white);
$my_image = imagecreatetruecolor($width, $height);
imagefill($my_image, 0, 0, 0xFFFFFF);
// adds noise
for ($c = 0; $c < 50; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}
$x = rand(10,12);
$y = rand(10,15);
$rand_string = rand(1000,9999);
//imagestring($my_image, $font, $x, $y, $rand_string, 0x000000);
imagettftext ($my_image, 22, $angle,10, 27, $black, $dir."arial.ttf", $rand_string);
setcookie('tntcon',(md5($rand_string).'a4xn'));
imagejpeg($my_image);
imagedestroy($my_image);
?>
联系表:
<img src="verification.php?<?php echo '<span>'.rand(0,9999).'</span>';?>" alt="Anti spam verification" class="verify" />
- 该字体位于标题为“fonts”的根文件夹中,
感谢大家的输入。
Having a hard time implementing a script I came across for a Captcha code. Not too familiar with PHP so any help would be awesome.
Problem: Captcha Image does not show up on the live server, but does on my local server.
Verification File:
<?php
header('Content-type: image/jpeg');
$width = 90;
$height = 30;
$dir = getcwd().'/fonts/';
$black = imagecolorallocate($my_image, 0, 0, 0);
$angle = rand(0,3);
imagefilledrectangle($image,0,0,399,99,$white);
$my_image = imagecreatetruecolor($width, $height);
imagefill($my_image, 0, 0, 0xFFFFFF);
// adds noise
for ($c = 0; $c < 50; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}
$x = rand(10,12);
$y = rand(10,15);
$rand_string = rand(1000,9999);
//imagestring($my_image, $font, $x, $y, $rand_string, 0x000000);
imagettftext ($my_image, 22, $angle,10, 27, $black, $dir."arial.ttf", $rand_string);
setcookie('tntcon',(md5($rand_string).'a4xn'));
imagejpeg($my_image);
imagedestroy($my_image);
?>
Contact Form:
<img src="verification.php?<?php echo '<span>'.rand(0,9999).'</span>';?>" alt="Anti spam verification" class="verify" />
- The font is located in a root folder titled "fonts"
Thank you for your input everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的“实时”服务器已关闭
display_errors
。这意味着它不会向您显示有关出现问题的错误。您需要检查 PHP 错误日志。我的猜测是没有安装GD。如果您使用 Apache,它应该位于
/var/log/apache2
中。如果没有,您可以通过创建 PHP 信息文件来询问 PHP,以查看设置是什么。I would assume your "live" server has
display_errors
off. That means it won't show you the error about what is going wrong. You need to check the PHP error log. My guess is that GD isn't installed.It should be in
/var/log/apache2
if you are using Apache. If not, you can ask PHP by creating a PHP info file to see what the setup is.