[Welcome] [TitleIndex] [WordIndex

Problem

You wish to check if the user has any cookies set from previous interactions with your application.

Solution

To retrieve a cookie with a given name, use the quixote.get_cookie() function.

from quixote import get_cookie
...
     login_time = get_cookie('login_time')

get_cookie() returns a string containing the cookie's value; if no such cookie exists, get_cookie() returns None. You can also specify a different default value:

    login_time = int(get_cookie('login_time', time.time()))

Discussion

See CookieSecurity for a discussion of security considerations related to cookies.


CategoryCookbook


2010-09-22 22:14