Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
上载到服务器时无法加载php验证码_Php - Fatal编程技术网

上载到服务器时无法加载php验证码

上载到服务器时无法加载php验证码,php,Php,关于本地PC中的验证码工作正常,但上传到服务器时(CentOS5.5) 无法加载PHP验证码 这是php代码调用get_captcha.php: $('#captcha-refresh').click(function() { change_captcha(); }); function change_captcha() { document.getElementById('captcha').src="get_captcha.php?rnd=" + Math

关于本地PC中的验证码工作正常,但上传到服务器时(CentOS5.5)

无法加载PHP验证码

这是php代码调用get_captcha.php:

$('#captcha-refresh').click(function() {  
  change_captcha();
});

function change_captcha()
{           
  document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();
}
for ($i = 0; $i < 4; $i++) 
{
    $word_1 .= chr(rand(97, 122));
}
for ($i = 0; $i < 4; $i++) 
{
    $word_2 .= chr(rand(97, 122));
}

$_SESSION['random_number'] = $word_1.' '.$word_2;
$dir = 'fonts/';
$image = imagecreatetruecolor(165, 50);
$font = "recaptchaFont.ttf"; // font style
$color = imagecolorallocate($image, 0, 0, 0);// color
$white = imagecolorallocate($image, 255, 255, 255); // background color white
imagefilledrectangle($image, 0,0, 709, 99, $white);
imagettftext ($image, 22, 0, 5, 30, $color, $dir.$font, $_SESSION['random_number']);
header("Content-type: image/png");
imagepng($image);  
$_SESSION['random_numberafter'] = $_SESSION['random_number'];
获取\u captcha.php:

$('#captcha-refresh').click(function() {  
  change_captcha();
});

function change_captcha()
{           
  document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();
}
for ($i = 0; $i < 4; $i++) 
{
    $word_1 .= chr(rand(97, 122));
}
for ($i = 0; $i < 4; $i++) 
{
    $word_2 .= chr(rand(97, 122));
}

$_SESSION['random_number'] = $word_1.' '.$word_2;
$dir = 'fonts/';
$image = imagecreatetruecolor(165, 50);
$font = "recaptchaFont.ttf"; // font style
$color = imagecolorallocate($image, 0, 0, 0);// color
$white = imagecolorallocate($image, 255, 255, 255); // background color white
imagefilledrectangle($image, 0,0, 709, 99, $white);
imagettftext ($image, 22, 0, 5, 30, $color, $dir.$font, $_SESSION['random_number']);
header("Content-type: image/png");
imagepng($image);  
$_SESSION['random_numberafter'] = $_SESSION['random_number'];
($i=0;$i<4;$i++)的

{
$word_1.=chr(兰特(97122));
}
对于($i=0;$i<4;$i++)
{
$word_2.=chr(兰特(97122));
}
$\u会话['random\u number']=$word\u 1.'.$word\u 2;
$dir='font/';
$image=imagecreatetruecolor(165,50);
$font=“recaptchaFont.ttf”;//字体样式
$color=imagecolorallocate($image,0,0,0);//颜色
$white=imagecolorallocate($image,255,255,255);//背景色白色
imagefilledrectangle($image,0,070999,$white);
imagettftext($image,22,0,5,30,$color,$dir.$font,$\u SESSION['random\u number']);
标题(“内容类型:图像/png”);
imagepng($image);
$_会话['random_numberrafter']=$_会话['random_numbers'];

检查您的服务器中是否安装了GD库。您可以使用phpinfo()进行检查


尝试使用随机数运行文件get_captcha.php,查看是否显示图像。谢谢

您的服务器上有任何php错误吗?您得到的响应是什么?没有。但它在服务器中不显示captchar图像,但本地可以。为什么?本地和服务器使用相同的配置?本地使用VMware中的Windows 7和服务器用户CentOS5.5。我不熟悉Windows,但对于CentOS,我建议使用错误报告(E_ALL)和ini_集(“显示错误”,1);然后再试一次(可能还会对标题进行注释),看看您在Centos 5.5中得到了什么是尚未安装的GD如何安装?我尝试了yum安装php-gd,但没有找到。此链接可能会有所帮助。浏览所有评论。谢谢