1
在我的项目,我想从2档访问会话数据,位于2名不同的目录:无法访问会话数据
/site/page.extension.php <-- initializes the session and writes data to it
- also sets a cookie with session_id() and session_name()
/extension/ajax_handler.php <-- tries to access the session data, session_id()
- and session_name() are set via cookie and return the correct values
现在,我的问题是,即使SESSION_ID()和session_name()在两个文件中都是相同的,我不能访问会话数组,它只是返回一个空数组。
我的代码: page.extension.php:
session_start();
setcookie("psc_session", session_id(), strtotime("+20 minutes"), "/");
setcookie("psc_session_name", base64_encode(session_name()), strtotime("+20 minutes"), "/");
$_SESSION['uid'] = system::current_user_id();
ajax_handler.php:
session_id($_COOKIE['psc_session']);
session_name(base64_decode($_COOKIE['psc_session_name']));
session_start();
print_r($_SESSION); // => array(0) { }
我真的很感激任何帮助! 问候!
更新: 我试过设置在page.extension.php使用这个会话cookie PARAMS:
$url = str_replace("http://", '', current_url(false)); // returns the current domain
session_set_cookie_params(10800, "/", $url, 0, 1);
如果我现在访问我收到(在ajax_handler.php)session_get_cookie_params:
print_r(session_get_cookie_params()); // =>
Array
(
[lifetime] => 0
[path] =>/
[domain] =>
[secure] =>
[httponly] =>
)
这是为什么发生?
什么是'system :: current_user_id();'? – Neal 2011-12-23 13:56:06
它只是返回当前登录用户的数字ID(cookie) – n0pt3x 2011-12-23 13:57:24
这里有个有趣的方法是什么原因? – Neal 2011-12-23 14:01:36