[mod_python] Sessions: Confused: Newbie

MCL Systems mcl.office at googlemail.com
Mon Feb 4 08:19:21 EST 2008


I thought I was understanding sessions but the following did not work as I
expected.

I was expecting the first execution to create a session with a PID of 666
and a Hits Value of 1 and on each refresh of that page in the same browser
to increment the hit counter, but the 'is_new' test, returns true every
time.  I have tried this on several computers and with different browsers,
but always the same result.

Where have I gone wrong ?

Richard

MOD_PYTHON, Apache, PYTHON 2.5

Code =====================================
from mod_python import Session, util

def index(req):
    main(req)

def main(req):
    mySess = Session.Session(req)
    if mySess.is_new():
        pid = 666
        mySess['pid'] = str(pid)
        mySess['hits'] = 1
        req.write("NEW Session PID: %s <BR>\n" % mySess['pid'])
        req.write("Hits: %s <br>\n" % mySess['hits'])
    else:
        mySess['hits'] +=1
        req.write("OLD Session PID: %s <BR>\n" % mySess['pid'])
        req.write("Hits: %s <br>\n" % mySess['hits'])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20080204/c4a6affb/attachment.html


More information about the Mod_python mailing list