在Codeigniter中重定向后会话丢失
2022-08-30 20:09:10
我使用codeigniter作为框架。
首先,我使用,但当我更改为我的IP地址时,登录功能不再起作用。我发现重定向到另一个控制器后会话丢失。localhost
这是结果print_r($this->session->all_userdata());
[session_id] => 7b00fa0f8790f48d24446f9eb4e6aab2
[ip_address] => 10.42.68.71
[user_agent] => Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1
[last_activity] => 1285962398
[user_data] =>
如您所见,它没有任何数据传递到,但它是在我测试时重定向之前设置的。user_data
我将控制器分成两个,第一个是用户 - >登录函数的处理程序,另一个是我从用户控制器重定向的链接的哪个处理程序。
users.php
(第一个控制器):
$this->load->model('users_model');
$this->load->model('mymodel');
$this->load->database();
$email = $this->input->post('email');
$pass = $this->input->post('password');
$type = $this->input->post('type');
// Authenticate the user
$userdata = $this->users_model->auth_user($email,$pass,$type);
if($userdata)
{
$data = array('FIRSTNAME' => $userdata->FIRSTNAME,
'LASTNAME' => $userdata->LASTNAME,
'EMAIL' => $userdata->EMAIL,
'LOGIN' =>TRUE, 'TYPE' => $type);
$this->session->set_userdata($data);
redirect('planner/view_system','refresh');
}
planner.php
(第二个控制器):
function __construct() {
parent::__construct();
if ( ! ($this->session->userdata('LOGIN')))
{
print_r (var_dump($this->session->userdata('FIRSTNAME')));
print_r($this->session->all_userdata());
}
$this->load->helper(array('form','html','url'));
这是我的配置
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 300;