您好,欢迎访问一九零五行业门户网

php如何在进入页面的时候自动刷新一次验证码

页面直接进入login页面的时候无法获取到$_session[auth]值,只能刷新一次验证码才能获取到值,怎么才能在用户访问的时候自动刷新一次验证码,求大神支招。。。
验证码 /includes/rand_func.php'/>

回复讨论(解决方案) 哪里获取到$_session[auth]值?
if(!empty($_get[action])) $post=$_get;else $post=$_post;if(!empty($_get['forward'])&&strpos($_get['forward'],'script')>0) header(location:login.php);//全if(!empty($post[action])&&$post[action]==submit){ include_once(includes/global.php); include_once(includes/smarty_config.php); include_once(config/reg_config.php); if(strtolower($_session[auth])!=strtolower($post[randcode])&&empty($post['first_index'])&&empty($post['connect_id'])) { header(location: login.php?erry=-3);//证 exit(); }
直接访问login.php页面$_session[auth]会为空,如果是从主页访问然后到登录页面$_session[auth]就会得到验证码的值
$_session[auth] 是由 rand_func.php 产生的
直接进入本身就不会有验证码,因为不是提交过来的
为什么刷新一次验证码验证码就会提交过来?怎么才能进入登录界面就提交呢?
像斑竹说的,session设置是发生在用户下载页面后请求验证码图片时,第一次请求php当然看不到验证码~
而且我对你的问题理解有点歧义...你是说第一次 访问login页面想获取到session,还是说第一次 提交验证码时获取不到session?
另外验证码的url最好加个随机数防止缓存,包括js换验证码图片的那个函数
估计是图片缓存问题。
/includes/rand_func.php ?{time()}'/>
改成这样看看。
当我访问登录页面的时候$_session[auth]的值为空
下面是验证码代码
width=$width; $this->height=$height; $this->codenum=$codenum; } function outimg() { //输出头 $this->outfileheader(); //产生验证码 $this->createcode(); //产生图片 $this->createimage(); //设置干扰像素 $this->setdisturbcolor(); //往图片上写验证码 $this->writecheckcodetoimage(); imagepng($this->checkimage); imagedestroy($this->checkimage); } private function outfileheader() { header (content-type: image/png); } private function createcode() { $this->checkcode = strtoupper(substr(md5(rand()),0,$this->codenum)); } private function createimage() { $this->checkimage = @imagecreate($this->width,$this->height); $back = imagecolorallocate($this->checkimage,255,255,255); $border = imagecolorallocate($this->checkimage,0,0,0); imagefilledrectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$back); // 白色底 imagerectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$border); // 黑色边框 } private function setdisturbcolor() { for($i=0;$idisturbcolor = imagecolorallocate($this->checkimage, rand(0,255), rand(0,255), rand(0,255)); imagesetpixel($this->checkimage,rand(2,128),rand(2,38),$this->disturbcolor); } } private function writecheckcodetoimage() { for ($i=0;$icodenum;$i++) { $bg_color = imagecolorallocate ($this->checkimage, rand(0,255), rand(0,128), rand(0,255)); $x = rand(0,7)+floor($this->width/$this->codenum)*$i; $y = rand(0,$this->height-15); imagechar ($this->checkimage, rand(5,8), $x, $y, $this->checkcode[$i], $bg_color); } } function __destruct() { unset($this->width,$this->height,$this->codenum); }}//===============================$width=$_get['w']?$_get['w']:80;$height=$_get['h']?$_get['h']:33;$image = new validationcode($width,$height,'4'); $image->outimg();$_session[auth] = $image->checkcode;?>
$_session[auth]的值首次访问会为空,刷新一次才会显示出来。。。
删除第5行的 $_session['auth'] = $randcode;
第75、76行的
$width=$_get['w']?$_get['w']:80;
$height=$_get['h']?$_get['h']:33;
改为
$width = isset($_get['w']) ? $_get['w'] : 80;
$height = isset($_get['h']) ? $_get['h'] : 33;
还是不行。。。。
验证码图片出不来吗?
validationcode类单独放在一个文件,并且单独方法a生成验证码,
需要的时候直接调用a方法,记得将类的$_session['auth'] = $randcode;去掉。
检查文件是否是含有bom头
其它类似信息

推荐信息