[mod_python] Sessions: Confused: Newbie

Jim Gallacher jpg at jgassociates.ca
Mon Feb 4 12:34:03 EST 2008


Make sure you call mySess.save(), otherwise the session is never saved 
and you'll get a new session on every request.

Jim

MCL Systems wrote:
> 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'])
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python


More information about the Mod_python mailing list