session儲存驗證碼的有關問題
來源:互聯網
上載者:User
session儲存驗證碼的問題
我在code頁面產生驗證碼的原字元 儲存到session中 從另一個頁面調用 怎麼會是空呢? 奇怪
code 的來源程式
//checkNum.php
session_start();
function random($len)
{
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();//配置亂數種子
$strs="";
for($i=0;$i <$len;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
/*
2 名 稱:strtoupper
3 功 能:字串全轉為大寫\r
4 傳回值:字串
5 語 法:strtoupper(string str);
6 說 明:本函式將字串 str 全部變大寫字串。\r
7 範 例:
8 strtoupper("ab2cd4efg"); 結果為AB2CD4EFG
9 strtoupper("ab1cde4fg"); 結果為Ab1CDE4fg
10
11 */
return strtoupper($strs);
}
$str=random(4); //隨機產生的字串
$width = 50; //驗證碼圖片的寬度
$height = 25; //驗證碼圖片的高度
/*
Content-Type: xxxx/yyyy
Location: xxxx:yyyy/zzzz
Status: nnn xxxxxx
*/
@header("Content-Type:image/png");
$_SESSION["code"] = $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["code"] = $str;
session_destroy();
?>
從另一個頁面調用$_SESSION["code"] 居然為空白? 為什麼
------解決方案--------------------
session_destroy();
你都刪除session了,另一個頁面怎麼會有session的內容?
------解決方案--------------------
session_destroy(); 暈,還沒取就登出session()你怎麼取?》