[mod_python] Cookies

Bo Lorentsen bl at netgroup.dk
Thu Jul 26 16:54:26 EST 2001


riesch at nieuw.nl wrote:

> I'm currently making a web-site with mod-python and since I want to make use of cookies, I was wondering how I can set a cookie.
> I've been looking through the documentation provided on the web-site, but I'm not able to find something. So if anyone could give me pointer, or even better comething that works, I'd be much obliged.

You find them in the header fields (headers_in / headers_out ) in the Request class.

If you like to set a cookie you do something like this :

    req.headers_out[ "Set-Cookie" ] = "my_session_id=42"

and the next time this user sends back a request back to you ( and if he support it) it will contain it in your input headers, and you will be able to fetch it like this :

    raw_cookie = req.headers_in[ "Cookie" ]

Now you only need to parse the input cookie string (raw_cookie), that have the syntax as descried in RFC-2109.

mod_python does not have any helper classes for either in- or outgoing cookies, but the format is strait forward, even I could make one :-)

Hope this helped

Regards

/BL




More information about the Mod_python mailing list