2
我有2个Codeigniter应用程序,我们称之为CI-A和CI-B。如何检查从一个codeigniter应用程序的会话/用户数据到另一个codeigniter应用程序
- CI-A不使用会话库。
- CI-B使用会话库。
- CI-A和CI-B都使用Codeigniter 3.x.
- CI-A和CI-B文件都放在同一台服务器和同一个域中。
如何让CI-A检查CI-B中是否有活动的会话/用户数据?
谢谢!
我有2个Codeigniter应用程序,我们称之为CI-A和CI-B。如何检查从一个codeigniter应用程序的会话/用户数据到另一个codeigniter应用程序
如何让CI-A检查CI-B中是否有活动的会话/用户数据?
谢谢!
我正在自己解决这个问题。
首先,确保您将会话数据存储在数据库中。不是文件。在这种情况下,CI-A和CI-B都使用相同的数据库。
二,CI-B,你需要得到的Cookie ID
$this->load->helper('cookie');
$cookie_name = $this->config->item('sess_cookie_name'); //cookie name
$key = $this->input->cookie($cookie_name); //get cookie id
三,CI-A,你需要确认提交的CI-B的$key
。
$save_path = $this->config->item('sess_save_path'); //session table name
$this->load->helper('cookie');
$key = $this->input->post('key'); //submitted from CI-B
//dirty solution
$this->db->where('id', $key);
$query = $this->db->get($save_path);
$data = $query->row();
if (!empty($data)) {
//session exist
//code below are from external source. Even the author were saying it is a horrible solution: http://forum.codeigniter.com/thread-61330.html
$session_data = $data->data;
$return_data = array();
$offset = 0;
while ($offset < strlen($session_data)) {
if (!strstr(substr($session_data, $offset), "|")) {
throw new Exception("invalid data, remaining: " . substr($session_data, $offset));
}
$pos = strpos($session_data, "|", $offset);
$num = $pos - $offset;
$varname = substr($session_data, $offset, $num);
$offset += $num + 1;
$data = unserialize(substr($session_data, $offset));
$return_data[$varname] = $data;
$offset += strlen(serialize($data));
}
return $return_data;
} else {
//session not exist
return FALSE;
}
如果您发现任何错误,请对上述代码进行更正。谢谢!
这有帮助吗? http://stackoverflow.com/questions/14611545/preserving-session-variables-across-different-domains – codisfy
@codeHeart我会看看。谢谢。 – mokalovesoulmate
你有没有尝试在db中保存你的会话? –