mod_python and PHP sharing same session

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott

    #1

    mod_python and PHP sharing same session

    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 Sesssion(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.

    Has anyone attermpted what I am trying to perform and if so a short
    snippet of code or explanation of how to interface to PHP session via
    mod_python would be great. I am not an experiecne PHP users but have
    used mod_python extensively.
    Scott

  • Diez B. Roggisch

    #2
    Re: mod_python and PHP sharing same session

    Scott wrote:
    [color=blue]
    > 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 Sesssion(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.[/color]

    Where did you read that? I seriously doubt that - simply because the
    internal representations of data stored in sessions are most likely
    incompatible between python and php - not sure what mod_pythonuses, but I
    guess pickle. And php will use whatever php uses.

    So - if you already know the session file, you'd might be able to parse it
    yourself. Alternatively, you might consider using cookies for the shared
    state.

    Diez

    Comment

    • Jim Gallacher

      #3
      Re: mod_python and PHP sharing same session

      Scott wrote:[color=blue]
      > 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 Sesssion(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.
      >
      > Has anyone attermpted what I am trying to perform and if so a short
      > snippet of code or explanation of how to interface to PHP session via
      > mod_python would be great. I am not an experiecne PHP users but have
      > used mod_python extensively.
      > Scott[/color]

      It shouldn't be a suprise that this doen't work. Mod_python stores its
      session data as a python pickle. PHP stores its session data as... well
      I have no idea, but I'm pretty sure it won't be a python pickle. ;)
      Mod_python creates a new session if it can't load valid session data
      from the dbm file, which will always be the case here as that file
      contains PHP formatted session data.

      You have 2 choices: Rewrite PHP session handling to write the data as a
      python pickle, or subclass mod_python BaseSession to read the PHP data
      format. Once that's done you'll need to figure out how to handle
      session locking between the 2 modules, which may not be trivial.

      I'd suggest joining the mod_python mailing list if you want to discuss
      this in detail.

      Jim

      Comment

      Working...