Here is the way to implement sessions .
You can genearate a random number using a rand module in python and then
keep on passing with your links like 5.cgi?q=2345345 and insert it into
database when it is generated and then at the top of each script check whether
it is that number or not.
if not equal then expired otherwise its okay………
But there is drawback you can visit previous pages by backspace in browser.