mod_python and PHP sharing same session

K Raghu Prasad prasad.raghu.k at gmail.com
Tue Apr 4 14:24:51 EDT 2006


Scott wrote:
 > I am trying to get a mod_python application to read an existing PHP
 > session.  I need some data that was set in the session by the PHP
 > application.  I am using the mod_python Session class but even when I
 > specify the session id that PHP uses the Session(req, sid) call
 > returns a new session id.  The session file exists in /tmp as
 > mp_sess.dbm and I have verified that PHP is reading/writing it and from
 > what I have read mod_python will use the same file.  I have used the
 > PythonOption session DbmSession in the Apache configuration to force
 > this and specified the filename as well but to no avail.

PHP and Python stores the session data differently. One way to fix this
problem without the issues of managing file locks is to use override
file based session handler of PHP with database based one. You can
use MySQL to store this data. Then you need to write a parser in Python
to parse the session data of PHP. Since this data is plain text, you don't
have to do any reverse engineering to understand its format. Once both
these things are ready, you can access the values stored by PHP application
from the Python one.

By the way, won't it be easy to use cookies to shared data between these
two applications?

Raghu



More information about the Python-list mailing list