最近我在使用我网站的管理区域时遇到了问题。似乎有会话问题。要查看$_SESSION
发生了什么,我创建了以下脚本:
<?
session_start();
mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE_NAME");
if (isset($_SESSION)) {
echo '<pre>session var:<br/>';
var_dump($_SESSION);
$perm = mysql_fetch_assoc(mysql_query("SELECT * FROM `perm_groups` WHERE `id` = '".$_SESSION['perm']."'"));
echo '<br/><br/>permission var:<br/>';
var_dump($perm);
echo '</pre>';
} else {
echo 'no session set';
}
?>
$ _ SESSION ['perm']应该包含一个数字字符串,引用我拥有的权限组的ID(“1” - &gt;“admin”) 登录后,我手动调用脚本并获得此结果:
session var:
array(4) {
["user"]=>
&string(17) "sebastian.philipp"
["auth"]=>
&bool(true)
["perm"]=>
&string(1) "1"
["llog"]=>
&string(19) "2013-08-21 09:48:38"
}
permission var:
array(7) {
["id"]=>
string(1) "1"
["name"]=>
string(4) "admin"
["create_pages"]=>
string(1) "1"
["delete_pages"]=>
string(1) "1"
["edit_pages"]=>
string(1) "1"
["manage_users"]=>
string(1) "1"
["manage_img"]=>
string(1) "1"
}
按F5刷新页面时,会返回以下结果:
session var:
array(4) {
["user"]=>
&string(17) "sebastian.philipp"
["auth"]=>
&bool(true)
["perm"]=>
&array(7) {
["id"]=>
string(1) "1"
["name"]=>
string(4) "admin"
["create_pages"]=>
string(1) "1"
["delete_pages"]=>
string(1) "1"
["edit_pages"]=>
string(1) "1"
["manage_users"]=>
string(1) "1"
["manage_img"]=>
string(1) "1"
}
["llog"]=>
&string(19) "2013-08-21 09:48:38"
}
permission var:
bool(false)
再次刷新时,就像这样:
session var:
array(4) {
["user"]=>
&string(17) "sebastian.philipp"
["auth"]=>
&bool(true)
["perm"]=>
&bool(false)
["llog"]=>
&string(19) "2013-08-21 09:48:38"
}
permission var:
bool(false)
所以像$perm
这样的semms被写入$_SESSION['perm']
,这不应该发生。
我做错了什么?