用到的基本东西:
1.修改配置文件
config.php$config['encryption_key']2.加载session类$this->load->library('session');3.创建session$this->session->set_userdata($array);4.查看session$this->session->userdata('session名');5.删除session$this->session->unset_userdata('session名');例子:
views/login.php
用户登录页面
models/test_m.php
load->database(); } function user_select($uname) { $this->db->where('uname',$uname); $this->db->select('*'); $query=$this->db->get('user'); //var_dump($query->result());die; return $query->result(); }}?>
controllers/login.php
load->view("login");}function checklogin() {$this->load->model("test_m");$user=$this->test_m->user_select($_POST['uname']);if($user) {if($user[0]->upass==$_POST['upass']) {echo "密码正确";$this->load->library('session');$arr=array('uid'=>$user[0]->uid);$this->session->set_userdata($arr);echo $this->session->userdata('uid');}else {echo "密码错误";}}else {echo "用户不存在";}}function checksession() {$this->load->library('session');if($this->session->userdata('uid')) {echo "已经登录";}else {echo "没登录";}}function logout() { $this->load->library('session');$this->session->unset_userdata('uid');}}?>
哎,代码乱的无法直视啊
=>array数组的键和值
->对象的成员