Question

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']['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.

Was it helpful?

Solution 3

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top