spyce
home
license
community
download
examples
resources
wishlist
contrib (@sf)
documentation
intro
lang
runtime
modules
tags
install
exits
sourceforge
statistics
freshmeat

transparent transparent transparent
Examples
[[ Spyce ]]
Python Server Pages
by Rimon Barr

examples/session.spy
[[.import name=cookie]]
[[.import name=session args="'session_dir', '/tmp'"]]
<html><body>
  [[-- retrieve session information --]]
  [[\
    sessionid = cookie.get('session')
    if sessionid:
      num = session.get(sessionid)
      if num==None:
        sessionid = None
        num = 0
      else: num = int(num)
    else: num = 0
  ]]
  [[-- output --]]
  Your session ID was: [[=sessionid]]<br>
  [[num = num + 1]]
  You have visited this page [[=num]] time(s).<br>
  [[-- save session information for next time --]]
  [[\
    sessionid = session.set( num, 10, sessionid )
    if sessionid: cookie.set('session', sessionid)
  ]]
  Your session ID is now: [[=sessionid]]<br>
  Session expiration = 10 seconds.<br>
  <b>Note:</b> This example requires write access to 
  the /tmp directory to function correctly.
</body></html>
Run this code.
(requires Spyce-enabled web server)

Back to List of Examples


© 2002 Rimon Barr
email: rimon AT acm DOT org
Spyce Powered SourceForge Logo [[ Spyce ]]
Python Server Pages
version 1.3.10