|
本帖最后由 lary88 于 2013-4-20 12:11 编辑
配置文件中自动加载 session类
$autoload['libraries'] = array('session');
控制器开始保存数据
public function login() {
if (!empty($_POST['flag']) && $_POST['flag'] == 'adminlogin') {
$uname = isset($_POST['username']) && !empty($_POST['username']) ? addslashes(trim($_POST['username'])) : '';
$upass = isset($_POST['upwd']) && !empty($_POST['upwd']) ? sha1(trim($_POST['upwd'])) : '';
// 密码 7c4a8d09ca3762af61e59520943dc26494f8941b admins&123456-7
if ($uname == 'admins') {
if ($upass === '7c4a8d09ca3762af61e59520943dc26494f8941b') {
setcookie("admin", $uname, time() + 3600);
echo 1;
}
else
echo 2;
}else {
$this->load->model("Admin_model", 'admin_m');
$rt = $this->admin_m->checkAdmin(array('uname' => $uname, 'upassword' => $upass));
if (is_array($rt) && !empty($rt)) {
$this->session->set_userdata('uname',$uname);
echo 1;
} elseif ($rt === 2)
echo 2;
else
echo 3;
}
}
else
$this->load->view('admins/login');
}
这个是用户登录方法
在管理员列表方法中打印一下所有的session数据
//显示用户列表
public function showAdminList() {
var_dump($this->session->all_userdata('uname'));
$this->load->model('Admin_model', 'admin_m');
$data['adminl'] = $this->admin_m->getAdminlist();
$this->load->view('admins/adminlist', $data);
}
打印出的结果是:
file:///C:/Documents%20and%20Settings/Administrator/Application%20Data/Tencent/Users/1092543996/QQ/WinTemp/RichOle/$3%60~8%60FY7_G~SRXGZOQRT%7BM.jpg
array(5) { ["session_id"]=> string(32) "6f31f9a5de595d672983420535eb06fa" ["ip_address"]=> string(9) "127.0.0.1" ["user_agent"]=> string(65) "Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0" ["last_activity"]=> int(1366429798) ["user_data"]=> string(0) "" }
这是怎么回事啊? 根据信息session是开启了 但是怎么没有保存到数据?怎么解决啊?
|
|