|
本帖最后由 斯奈克 于 2012-2-17 03:20 编辑
这里是 用户控制器【登录,退出之类的】
PHP复制代码
function __construct (){
session_start();
parent ::__construct ();
header("content-type:text/html; charset=utf-8");
}
public function index (){
echo anchor ('admin','Go To Admin');
}
public function login (){
if(isset($_SESSION)){redirect ('home');}
$this->load->library('form_validation');
$this->form_validation->set_rules('user','帐号','required');
$this->form_validation->set_rules('pass','密码','required');
if($this->form_validation->run() !== FALSE){
$this->load->model('user_model');
$result = $this->user_model->CheckUser($this->input->post('user'),$this->input->post('pass'));
if($result !== FALSE){
$_SESSION['uid'] = $result['u_id'];
$_SESSION['user'] = $result['u_user'];
$_SESSION['name'] = $result['u_name'];
$_SESSION['level'] = $result['u_level'];
redirect ('home');
}
}
$this->load->view('login');
}
复制代码
这里是 首页控制器
PHP复制代码
class Home extends CI_Controller {
function __construct (){
parent ::__construct ();
header("content-type:text/html; charset=utf-8");
}
public function index (){
$link = (!isset($_SESSION)) ? anchor ('user/login','Go To Login') : anchor ('user/logout','Go To Logout');
$admin = (isset($_SESSION) && $_SESSION['level'] != 5) ? anchor ('user/info','Go To Info') : anchor ('admin','Go To Admin');
echo $admin .' '.$link.'<br />';
}
}
复制代码
这里的 SESSION 不能在别的控制器上用么?我只在 USER控制器里的 构造函数里 写了 session_start();
刚刚试过了,别的控制器上用不了,有没有直接全局使用啊?
根目录里的 INDEX.PHP里 添加 SESSION_START 安全不?可以那样写吗?
{:soso__11090708543365420450_2:}
|
|