[英]Codeigniter 3.0.0: Session gone after redirecting to other page
我有一些問題,我的代碼工作正常,但會話不是。 這里的代碼:
public function index()
{
if (isset($_POST['btnSubmit'])) {
$this->lm->username = $_POST['username'];
$this->lm->password = $_POST['password'];
$sql = sprintf("SELECT hakAkses, nip FROM user WHERE username = '%s' AND password = '%s'",
$this->lm->username,
$this->lm->password
);
$query = $this->db->query($sql);
$row = $query->row();
$sessData = array('nip' => $row->nip,
'hakAkses' => $row->hakAkses);
$this->session->set_userdata($sessData);
print_r($this->session->all_userdata());
if ($this->session->userdata('hakAkses') == 'ADMIN') {
redirect('Admin/index','refresh');
} else if ($this->session->userdata('hakAkses') == 'PENGAJAR'){
redirect('Pengajar/index','refresh');
} else {
redirect('Login','refresh');
}
} else {
$this->load->view('Login/LoginView');
}
}
當我在設置會話$this->session->set_userdata($sessData);
之后我做到了這$this->session->set_userdata($sessData);
。 但是當我再嘗試以其他形式打印時,會話已經消失了。
我的會話配置:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_sessios';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
好的原因是我每次重定向頁面時會話生成新會話。 怎么處理這個?
從你的代碼中不清楚為什么。 但是你可能忘了從其他頁面加載會話。 因此,請嘗試從autoload.php自動加載會話庫。 或者使用$this->load->library('session');
在控制器中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.