简体   繁体   English

如何从外部文件访问Codeigniter会话

[英]How to access codeigniter session from external files

我想从外部文件访问codeigniter会话,因此当我尝试从外部打印会话变量时,没有空数组

Codeigniter sessions are stored in a database table called ci_sessions unless you renamed it. 除非您重命名,否则ci_sessions会话将存储在名为ci_sessions的数据库表中。 Thus they are not accisible in the $_SESSION variable of PHP 因此,它们在PHP的$_SESSION变量中不可用

heres what you do 这是你的工作

  1. get the session ID from the cookie. 从Cookie获取会话ID。 The cookie containing the session id will be called ci_session unless you changed the value of sess_cookie_name in the config.php file 除非您在config.php文件中更改了sess_cookie_name的值,否则包含会话ID的cookie将称为ci_session
  2. from the database fetch the row from the ci_sessions table mentioned earlier and confirm that the clients ip_address and user_agent matches those in the row you just retrieved (this is for security reasons) 从数据库中获取前面提到的ci_sessions表中的行,并确认客户端ip_addressuser_agent与您刚获取的行中的客户user_agent匹配(这是出于安全原因)
  3. the actual session data will be held in the user_data column. 实际的会话数据将保存在user_data列中。 You will have to parse this and obtain the key/value pairs. 您将必须对此进行解析并获取键/值对。 I suggest finding the relevant function for this in the sessions.php file in codeigniters system folder. 我建议在codeigniters系统文件夹的sessions.php文件中找到与此相关的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM