Query String SID
Query string based session:
#!/usr/bin/env python import sha, time, cgi, os sid = cgi.FieldStorage().getfirst('sid') if sid: # If session exists message = 'Already existent session' else: # New session # The sid will be a hash of the server time sid = sha.new(repr(time.time())).hexdigest() message = 'New session' qs = 'sid=' + sid print """\ Content-Type: text/html\n <html><body> <p>%s</p> <p>SID = %s</p> <p><a href="./set_sid_qs.py?sid=%s">reload</a></p> </body></html> """ % (message, sid, sid)
To mantain a session you will have to append the query string to all the links in the page.
Save this file as set_sid_qs.py and run it two or more times. Try to close the browser and call the page again. The session is gone. The same happens if the page address is typed in the address bar.