验证码问题

z32109571 2011-04-06 11:32:36
<?php
session_start();
error_reporting(E_ALL & ~E_NOTICE);
$chars = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
$string = "";
for ($i = 0; $i < 5; $i++)
{
srand((double)microtime() * 1000000);
//srand()设置随机数种子,microtime获取当前时间的百万分之一
$rand = rand(0, strlen($chars) - 1);
$string.= substr($chars, $rand, 1); //截取字符串,只截取一个
}
//session_unregister("string"); //注销上一次使用的字符串
//session_register("string");
$_SESSION['code'] = $string;
header("Content-type: image/png"); //输出图形格式
$imagewidth = 120;
$imageheight = 30;
$im = imagecreatetruecolor($imagewidth, $imageheight); //创建一个图像流
$backcolor = imagecolorallocate($im, rand(220, 225), rand(220, 225), rand(220,
225)); //设置背景色
imagefilledrectangle($im, 0, 0, $imagewidth, $imageheight, $backcolor);
//填充一个长方形,坐标位于(0,0)
for ($i = 0; $i < 200; $i++)
{
$dotcolor = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255))
; //配置点的颜色
$x = rand(0, $imagewidth);
$y = rand(0, $imageheight); //产生随机坐标
imagesetpixel($im, $x, $y, $dotcolor); //填充点
}

for ($i = 0; $i < strlen($string); $i++)
{
$frontcolor = imagecolorallocate($im, rand(0, 120), rand(0, 120), rand(0, 120)
);
imagestring($im, 10, rand(20 * $i + 1, 20 * $i + 10), rand(0, 5), substr
($string, $i, 1), $frontcolor); //填充字符串,字体10号,坐标随机substr() 函数返回字符串的一部分。
//substr(string,start,length)
}

imagepng($im); //输出这个图形
imagedestroy($im); //销毁临时资源
exit();
?>
这是我写的一个验证码程序,在我电脑上能正常运行,但是在其他电脑上确提示的是下载,请问这个验证码怎么改,提示我开了GD库的!
...全文
107 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
z32109571 2011-04-08
  • 打赏
  • 举报
回复
有没有高手知道呀!
z32109571 2011-04-07
  • 打赏
  • 举报
回复
我已经写进Img标签还是不行!
liuji2006 2011-04-06
  • 打赏
  • 举报
回复
我电脑上也是显示正常 没看出有什么问题
gwn1902 2011-04-06
  • 打赏
  • 举报
回复
我电脑上面运行也木有问题哦
baiyu6396 2011-04-06
  • 打赏
  • 举报
回复
没看出来问题啊。
ImN1 2011-04-06
  • 打赏
  • 举报
回复
这个我觉得是客户端问题,直接打开可能会显示下载,如果写进<img>标签应该能显示

你尝试写进img标签在那台不能显示的机器上再测试一次看看

z32109571 2011-04-06
  • 打赏
  • 举报
回复
有高手知道这段代码怎么改吗?这是什么原因造成的!
ImN1 2011-04-06
  • 打赏
  • 举报
回复
我这里的结果是这样的

firefox4/opera11 直接识别为png并显示
ie6/chrome10 均只识别为php

ie6 第一次提示下载,刷新后显示
chrome10 显示

呵呵……
小在在 2011-04-06
  • 打赏
  • 举报
回复
你的机子是服务器吗

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧