怎么处理php验证码session值与图片的不一致,PHP 输出session 验证码与图片不同步,图片老是快一步,求解...

本帖最后由 Xdawei 于 2012-04-18 20:07:42 编辑

PHP 输出session 验证码与图片不同步,图片总是快一步,求解!

session_start();

function random($len)

{

$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

mt_srand();

$strs="";

for($i=0;$i

$strs.=$srcstr[mt_rand(0,35)];

}

return strtoupper($strs);

}

$str=random(4);

$width = 50;

$height = 25;

@header("Content-Type:image/png");

$_SESSION["captcha"] = $str;

//echo $str;

$im=imagecreate($width,$height);

$back=imagecolorallocate($im,0xFF,0xFF,0xFF);

$pix=imagecolorallocate($im,187,230,247);

$font=imagecolorallocate($im,41,163,238);

mt_srand();

for($i=0;$i<1000;$i++)

{

imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);

}

imagestring($im, 5, 7, 5,$str, $font);

imagerectangle($im,0,0,$width-1,$height-1,$font);

imagepng($im);

imagedestroy($im);

$_SESSION["captcha"] = $str;

?>

captcha.php

------解决方案--------------------

这个问题很诡异,最好的方法就是分开。

试试这个吧

checkcode.class.php

相关文章

相关视频

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值