xampp1.7.7无法打开验证码的图片(验证码的程序本身没有问题。因为我在我的室友那里成功执行了) php.ini里面的gd2已经打开了。就是不知道为什么画图显示图片的那些函数都无法显示图片。请问哪里还要设置?求。如何判断gd2库是否打开正常? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 phpinfo(); 查看你的gd库是否开启。。另外你打开错误显示功能看有没有错误提示。。 在 phpinfo中检查自己的php.ini文件是否是自己打开的那个文件. 文件编码也有可能造成图片不能正常显示,比如UTF8、UNICODE编码文件,默认情况下都BOM头,PHP在执行该文件时会把BOM头一起输出,造成图片数据错误。解决方法有两种:第一种:使用ASCII编码保存文件第二种:保存时设置为无BOM头模式(很多编辑器都有这个选项) 我的qq是249616294能不能在qq上教我。 function _code($_width = 75, $_height=25,$_rnd_code=4,$_flag=false){ for ($i=0;$i<$_rnd_code;$i++){ $_nmsg.=dechex(mt_rand(0,15)); } $_SESSION['code']=$_nmsg; $_img=imagecreatetruecolor($_width,$_height); $_white=imagecolorallocate($_img,255,255,255); imagefill($_img,0,0,$_white); if ($_flag){ $_black=imagecolorallocate(S_img,0,0,0); imagerectangle($_img,1,1,$_width-1,$_height-1,$_black); } for($i=0;$i<1;$i++){ $_rnd_color=imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); imageline($_img,mt_rand(0,$_width),mt_rand(0,$_height),mt_rand(0,$_width),mt_rand(0,$_height),$_rnd_color); } for($i=0;$i<100;$i++){ $_rnd_color=imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)); imagestring($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),'*',$_rnd_color); } for($i=0;$i<strlen($_SESSION['code']);$i++){ $_rnd_color=imagecolorallocate($_img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)); imagestring($_img,5,$i*$_width/$_rnd_code+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],$_rnd_color); } header('Content-Type:image/png'); imagepng($_img); imagedestroy($_img);}这是函数的原型。函数的调用_code(); 本帖最后由 xuzuning 于 2011-12-20 13:55:28 编辑 周围的几台电脑都可以成功执行,所以我把问题锁定在xampp,但是我不知道如何弄服务器本身。 今儿装xampp也出现这个问题了。把php.ini中的error_reporting 改为这个E_ALL & ~E_NOTICE,问题解决 asp.php.jsp三者有什么区别?和有什么关联? 文本框中的如何保留空格 如何在delphi运行途中响应事件 自动填入前一个工作日日期 PHP分页问题 PHP连接数据库问题,请大虾们救急!!! 请问PHP4如何实现类成员的共享? 请问PHP能读取注册表以判断某个软件是否安装吗? 表单传值,我怎么做哪里错了? 关于模式匹配的一个匹配中文的问题,无法解决,急!!!! centos 下使用 yum 安装php 5.2.17 无法使用mysql_connect、json_encode等函数 请教这个utf-8简单的页面,怎么从数据库里取的数据中文都是问号,试的办法都不行
解决方法有两种:
第一种:使用ASCII编码保存文件
第二种:保存时设置为无BOM头模式(很多编辑器都有这个选项)
for ($i=0;$i<$_rnd_code;$i++){
$_nmsg.=dechex(mt_rand(0,15));
}
$_SESSION['code']=$_nmsg;
$_img=imagecreatetruecolor($_width,$_height);
$_white=imagecolorallocate($_img,255,255,255);
imagefill($_img,0,0,$_white);
if ($_flag){
$_black=imagecolorallocate(S_img,0,0,0);
imagerectangle($_img,1,1,$_width-1,$_height-1,$_black);
}
for($i=0;$i<1;$i++){
$_rnd_color=imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imageline($_img,mt_rand(0,$_width),mt_rand(0,$_height),mt_rand(0,$_width),mt_rand(0,$_height),$_rnd_color);
}
for($i=0;$i<100;$i++){
$_rnd_color=imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),'*',$_rnd_color);
}
for($i=0;$i<strlen($_SESSION['code']);$i++){
$_rnd_color=imagecolorallocate($_img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));
imagestring($_img,5,$i*$_width/$_rnd_code+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],$_rnd_color);
}
header('Content-Type:image/png');
imagepng($_img);
imagedestroy($_img);
}
这是函数的原型。
函数的调用_code();