麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
一图形认证, SESSION落后图形数字一个节拍?
悬赏分:20 - 2007年08月22日

生成图形认证的代码如下: StringAuth.php [php] <?php /** * @name 生成图形认证的类 * @version 0.1 * **/ class StringAuth{ private $width; private $height; private $len; private $bgcolor; private $noise; private $noise_num; private $border; private $border_color; private $image; private $font_dir; private $code; //认证码 /** * @todo 完成必要的图形参数设置 * @param $width:高度 * @param $height * @param $len 生成数字的个数 * @param $bgcolor:高度 * @param $noise 是否要干扰码 true | fasle * @param $noise_num * @param $border * @param $border_color * @param $font_dir * */ function StringAuth($width,$height,$len,$bgcolor, $noise,$noise_num,$border,$border_color,$font_dir){ $this->width = $width; $this->height = $height; $this->len = $len; $this->bgcolor = $bgcolor; $this->noise = $noise; $this->noise_num= $noise_num; $this->border = $border; $this->border_color = $border_color; $this->font_dir = $font_dir; $this->AuthInit(); } /** * @return 数字图形 * */ function AuthInit(){ session_start(); $this->image = imageCreate($this->width, $this->height); $back = $this->getcolor($this->bgcolor); imageFilledRectangle($this->image, 100, 300, $this->width, $this->height, $back); $size = $this->width/$this->len; if($size > $this->height){ $size = $this->height; } $left = ($this->width-$this->len*($size+$size/10))/$size; for ($i = 0; $i < $this->len; $i++) { $randtext = rand(0, 9); $code .= $randtext; $textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100)); $font = $this->font_dir.rand(1,4).".ttf"; $randsize = rand($size-$size/10, $size+$size/10); $location = $left+($i*$size+$size/10); imagettftext($this->image, $randsize, rand(-18,18), $location, rand($size-$size/10, $size+$size/10), $textColor, $font, $randtext); } if($this->noise == true){ $this->setnoise(); } $_SESSION['code'] = $code; $bordercolor = $this->getcolor($this->bordercolor); if($this->border==true){ imageRectangle($this->image, 0, 0, $this->width-1, $this->height-1, $bordercolor); } // HTTP/1.1 header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", true); // HTTP/1.0 header("Pragma: no-cache"); if (function_exists("imagepng")) { header("Content-type: image/png"); imagepng($this->image); } elseif (function_exists("imagegif")) { header("Content-type: image/gif"); imagegif($this->image); } elseif (function_exists("imagejpeg")) { header("Content-type: image/jpeg"); imagejpeg($this->image); } else { die("No image support in this PHP server!"); } imagedestroy ($this->image); } /** * @param $color * @return $color * ***/ function getcolor($color) { $color = eregi_replace ("^#","",$color); $r = $color[0].$color[1]; $r = hexdec ($r); $b = $color[2].$color[3]; $b = hexdec ($b); $g = $color[4].$color[5]; $g = hexdec ($g); $color = imagecolorallocate ($this->image, $r, $b, $g); return $color; } function setnoise() { for ($i = 0; $i < $this->noise_num; $i++){ $randColor = imageColorAllocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255)); imageSetPixel($this->image, rand(0, $this->width), rand(0, $this->height), $randColor); } } } $x = new StringAuth(200,70,4,"#ffffff",true,400,true,"#cccccc","./font/"); ?> [/php] 引用的代码如下: [php] <?php session_start(); ?>
<?php echo $_SESSION['code']; ?>

[/php] 测试输出的图形数字和SESSSION的不一样, 而是落后一个节拍 但当 [php] if (function_exists("imagepng")) { header("Content-type: image/png"); imagepng($this->image); } [/php] 改为有图片存储, 而引用代码只引用存储的图片 [php]if (function_exists("imagepng")) { header("Content-type: image/png"); imagepng($this->image,"temp.png"); } [/php] 而引用代码为 [php] <?php session_start(); include("StringAuth.php"); ?>
<?php echo $_SESSION['code']; ?>
[/php] 请问下, 到底是哪里出了问题? 还是输出缓冲有问题

提问者:winday   08-22 16:04
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
47 + 67 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM