Cookies management

Cookies are little pieces of information stored locally into the client’s browser cookie cache. They are quite useful to store non-sensitive information and ask the browser to recall it (or them) at a later time: a typical example is the storage of some simple data like favourite color, to be requested for each visit in order to dynamically personalize the style sheet, without needing to engage complex preference management with login and sessions.

Obviously, it shouldn’t be used to store sensible user data, such as user names and passwords. Indeed, cookies has an important role in sessions management, because they are the preferred method to temporarily store the session ID. For further information about sessions and session management, see section SessionManagement.

Example

#cookies must be created valid only for /hello.pyhp
pyhp.cookies.defaults['path'] = '/hello.pyhp'

#create the cookie
c = pyhp.cookies.create('cookie_try')
c.data['my_value'] = 3 + 2

#cookie should expire in 10 seconds
c.set_attr('expires', time.strftime('%a, %d-%b-%Y %H:%M:%S GMT', time.gmtime(time.time()+10)))

#print the resulting cookie
print "SETTING COOKIE: %s<br/>" % c

For more examples, see the ‘’examples’’ folder.