I’m making somewhat of a “module” that gets included into another unrelated PHP application. In my “module” I need to use sessions. However, I get the ‘session has already been started…’ exception. The application that my “module” is included into is starting the session. If I cannot disable sessions in this application, what are my options? I’d like to use Zend_Session, but it seems upon first glance that it is not possible. However, maybe there is another way? Any ideas?
Thanks!
With PHP’s session implementation, there can only be one session at a time. You can use
session_idto check if there currently is a session:Now if there is already an active session, you could end it with
session_write_close, change the session ID’s name withsession_nameto avoid conflicts, start your session, and restore the old session when done:The only problem with this is that PHP’s session implementation does only send the session ID of the last started session back to the client. So you would need to set the transparent session ID (try
output_add_rewrite_var) and/or session cookie (seesetcookie) on your own.