开发者

Zend_Session_Namespace from non-Zend PHP

开发者 https://www.devze.com 2023-03-06 04:23 出处:网络
I need to integrate my no-framework code with my brand new Zend Application. But they need to share a session. The problem I am facing is - when I am setting the session variables from the non-zend ph

I need to integrate my no-framework code with my brand new Zend Application. But they need to share a session. The problem I am facing is - when I am setting the session variables from the non-zend php using

$_SESSION['MyApp']['开发者_Python百科user']=$user;

I cant access the session from the Zend Application, i tried both -

print_r($_SESSION['MyApp']['user']);

and

$myAppSession = new Zend_Session_Namespace('MyApp');
print_r($myAppSession->user);

Doesn't work. Info - I have

resources.session.name = "MyApp"

in my bootstrap ini file.


Zend_Session_Namespace is just a wrapper for $_SESSION so this should be straightforward. When you say it doesn't work, is the $_SESSION array empty? If so, make sure you are creating the sessions in the same way (i.e. using the same session storage, cookie name etc.).


You're confusing session name with ZF session namespaces.

The session name refers to the value stored in the session cookie and does not have any effect on the actual contents of $_SESSION.

For your apps to share a session, they both need to set the same name using session_name() or the session.name php.ini directive.


I found a way out, Zend Session has a different session id than normal PHP sessions, so what I did was to send the session id from zend with the request and start the session with that session id -

    if(isset($_REQUEST['sess_id'])) {
        $sess_id = $_REQUEST['sess_id'];
    }

    session_id($sess_id);
    session_start();

Its not beautiful code, but it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消