简体   繁体   English

PHP Captcha Imagettftext无法正常工作

[英]PHP Captcha Imagettftext Not Working

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. 对PHP不太熟悉,所以任何帮助都会很棒。

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" 字体位于名为“ fonts”的根文件夹中

Thank you for your input everyone. 谢谢大家的投入。

I would assume your "live" server has display_errors off. 我假设您的“实时”服务器关闭了display_errors That means it won't show you the error about what is going wrong. 这意味着它不会向您显示错误所在。 You need to check the PHP error log. 您需要检查PHP错误日志。 My guess is that GD isn't installed. 我的猜测是未安装GD。

It should be in /var/log/apache2 if you are using Apache. 如果您使用的是Apache,则它应位于/var/log/apache2 If not, you can ask PHP by creating a PHP info file to see what the setup is. 如果没有,您可以通过创建PHP信息文件来询问PHP,以查看设置是什么。

<?php phpinfo();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM