PHP 验证码 Imagettftext 不工作

发布于 2024-12-23 11:46:05 字数 1220 浏览 5 评论 0原文

在实现一个验证码脚本时遇到了困难。对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拧巴小姐 2024-12-30 11:46:05

我假设您的“实时”服务器已关闭 display_errors 。这意味着它不会向您显示有关出现问题的错误。您需要检查 PHP 错误日志。我的猜测是没有安装GD。

如果您使用 Apache,它应该位于 /var/log/apache2 中。如果没有,您可以通过创建 PHP 信息文件来询问 PHP,以查看设置是什么。

<?php phpinfo();

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.

<?php phpinfo();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文