验证码刷新时,session为什么不改变?
rarny 2014-06-05 12:44:06 现在我点击刷新过验证码后,页面上echo出来的$_SESSION["check_checks"]值始终第一次的时候的值,以后再刷新验证码也不变,为什么session值不能实时刷新呢,大家帮忙看一下,谢谢?(代码如下)
验证码php:code.php
<?php
session_start();
header("content-type:image/png");
$image_width = 70;
$image_height = 40;
for ($i=0; $i < 4; $i++) {
$new_number.=dechex(rand(0,15));
}
$_SESSION["check_checks"] = $new_number;
$num_image = imagecreate($image_width, $image_height);
imagecolorallocate($num_image, 237, 248, 248);
for($i=0;$i<strlen($_SESSION["check_checks"]);$i++){
$font = mt_rand(1,5);
$x = mt_rand(1,8) + $image_width*$i/4;
$y = mt_rand(2,$image_height/2);
$color = imagecolorallocate($num_image, mt_rand(0,100), mt_rand(0,150), mt_rand(0,200));
imagestring($num_image, $font, $x, $y, $_SESSION["check_checks"][$i], $color);
}
imagepng($num_image);
imagedestroy($num_image);
?>
页面部分:
<div class="regist_yzm" id="regist_box" style="float:left;width:92px;">
<img src="code.php">
</div>
<?php session_start();echo $_SESSION['check_checks'] ?>
<script type="text/javascript">
$('#regist_box img').on('click',function(){
$(this).attr('src','code.php?m='+Math.random());
});
</script>