[英]Share Sessions Between Zend and Pure PHP on Same Domain
I have two folder like this: 我有两个这样的文件夹:
And Drupal has been installed in root. 并且Drupal已安装在root用户中。
Now, I want to create a session in second path and use it in zend. 现在,我想在第二条路径中创建一个会话,并在zend中使用它。 I tried some different ways to do it but failure was the resut! 我尝试了几种不同的方法来做,但是失败才是结果!
I check session_id and session_save_path for both which are same now. 我现在检查session_id和session_save_path两者是否相同。
In second folder I have this: 在第二个文件夹中,我有这个:
session_start();
session_id($_COOKIE[PHPSESSID]);
$_SESSION[user] = 123;
And in first one: 在第一个中:
$someNamespace = new Zend_Session_Namespace('ns');
//......
session_id($_COOKIE[PHPSESSID]);
print_r($_SESSION);
But it returns empty array! 但是它返回空数组!
Also I tried this in second folder: 我也尝试在第二个文件夹中:
set_include_path ( $zend_path );
include_once $zend_path . '/Session.php';
$user = new Zend_Session_Namespace('user');
But I get this error: (I can't prevent running session_start to escape this error) 但我收到此错误:(我无法阻止运行session_start来逃避此错误)
Zend_Session_Exception: session has already been started by session.auto-start or session_start() in Zend_Session::start() (line 462 of C:\\wamp\\www\\zend_app\\library\\Zend\\Session.php). Zend_Session_Exception:会话已经由Zend_Session :: start()中的session.auto-start或session_start()启动(C:\\ wamp \\ www \\ zend_app \\ library \\ Zend \\ Session.php中的第462行)。
Now my question is that how can I share it with zend? 现在我的问题是,我如何与zend共享它? Does Zend use special handler? Zend是否使用特殊处理程序? How can I use it in pure php code? 如何在纯PHP代码中使用它?
Take a look at: 看一眼:
http://framework.zend.com/manual/1.12/en/zend.session.basic_usage.html http://framework.zend.com/manual/1.12/zh/zend.session.basic_usage.html
$myNamespace = new Zend_Session_Namespace('myNamespace');
// $myNamespace corresponds to $_SESSION['myNamespace']
Get rid of session_id()
, you don't need to give PHP the cookie, that's handled automatically. 摆脱session_id()
,您不需要给PHP cookie,它是自动处理的。
I just tried this in a ZF controller: 我只是在ZF控制器中尝试过此操作:
$session = new Zend_Session_Namespace('ns');
$session->foo = "bar";
print_r($_SESSION);
And this is what I got out: 这就是我得出的结论:
Array
(
[ns] => Array
(
[foo] => bar
)
}
So I can access $_SESSION['ns']['foo']
now in pure PHP. 因此,我现在可以使用纯PHP访问$_SESSION['ns']['foo']
。 I can also set values in pure PHP: 我还可以在纯PHP中设置值:
$_SESSION['ns']['baz'] = "quz";
And later access in ZF: 后来在ZF中访问:
echo $session->baz; // gives me "quz"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.