- Code: Select all
# initialize cookie and retrieve cookie from clients browser
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
if cookie.get('ID') is not None:
cookieID = cookie['ID'].value
cookieID = random.randrange(0, 9999)
cookie['ID'] = cookieID
cookie['ID']['domain'] = ".superhost.gr"
cookie['ID']['path'] = '/'
cookie["ID"]["expires"] = 60*60*24*365 # this cookie will expire in a year
print( cookie )
print( '''Content-type: text/html; charset=utf-8\n''' )
I use this code to retrive or set a cookie to the visitor's browser if present and identify him bu it.
All work well except the situation where the user visits my webpage by clicking a backlink on another wbpage.
Then for some reason the cookieID changes to another value thus a new entry appears into the database when insert happens.
What can i do about that?