- 論壇徽章:
- 0
|
有兩個(gè)php文件a.php 及 b.php如下
a.php
- <?php
- session_start();
- function random($len)
- {
- $srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- mt_srand();
- $strs="";
- for($i=0;$i<$len;$i++){
- $strs.=$srcstr[mt_rand(0,35)];
- }
- return strtoupper($strs);
- }
- $str=random(6);
- $_SESSION['code'] = $str;
- $_SESSION['test'] = session_id();
- $width = 68;
- $height = 25;
- @header("Content-Type:image/png");
- $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);
- ?>
復(fù)制代碼
b.php
- <?php
- session_start();
- echo "<img src=a.php border=0 align=absbottom>";
- echo "</br>session code= " . $_SESSION['code'];
- ?>
復(fù)制代碼
執(zhí)行http://localhost/b.php時(shí)顯示的驗(yàn)證碼總是前一次的值,不知道是什么問(wèn)題。
比如,打開(kāi)刷新兩次后分別顯示如下:
![]()
![]() |
|