Re: About retrieving cookies...
Martijn Moeling <[email protected]> Thu, 4 Mar 2010 17:39:36 +0100
| Newsgroups | gmane.comp.python.mod_python |
|---|---|
| Message-ID | <[email protected]> |
Hi Victor,
Cookies are send to the browser in the HTTP header, so yes set them befor=
e any write operation as the headers are send at the first write.
Next, Why are you trying to get the contents from a cookie which is store=
d on the "client" via a call to the server, it is not logical,=20
I suggest you read about cookies and how they work. I can give you a very=
long description about how cookies work but this is not mod_python relat=
ed.
If you really want to do this (I do not see any reason though). Google on=
"access cookies from javascript" or do a search on "document.cookie". Li=
ke Firefox (I think FF uses javascript for this too).
you CAN access it locally. Use Firebug (javascript debug plugin) to inves=
tigate stuff.
I hope this helps
Martijn
On Mar 4, 2010, at 4:49 PM, V=EDctor wrote:
> Dear all,
>=20
> I've got a bunch of problems using cookies. First, it seems that if
> you want to store a cookie, you MUST do it before any req.write()
> sentence, isn't it?
>=20
> Next... I've managed to store a simple cookie named "login_cookie"
> with value 100. I can see it in the cookies manager in firefox, and it
> has the right value. The cookie has an expiration time of 30 days from
> now.
>=20
> The problem is that... it's absolutely impossible to retrieve it from
> the browser.
>=20
> I have a small test page with this javascript function (it uses prototy=
pe):
>=20
> function accessPage(){
> new Ajax.Request(access_base_dir+'access', {
> =09
> method: 'post',
> =09
> onSuccess: function(response) {
> $("resultados").innerHTML =3Dresponse.responseText;
> },
> =09
> onFailure:function(response) {
> $("resultados").innerHTML=3D "Failed to access."+response.respons=
eText;
>=20
> }
> });
> =09
> }
>=20
> This function just asks 'access' to return the content. 'access' looks
> like this:
>=20
> @_session_getter
> def access(req):
> =09
> (logged,user_id) =3D getSessionData(req)
> =09
> all_cookies =3D Cookie.get_cookies(req)
> =09
> req.write("Access: " +str(all_cookies))
>=20
> And guess what, it only writes Access: {'pysid': } , the session
> cookie, but "login_cookie" is not anywhere.
>=20
> My apache config for this folder is:
>=20
>=20
> <Directory "htdocs/python/test">
> AddHandler mod_python .py
> PythonHandler mod_python.publisher
> PythonDebug On
> </Directory>
>=20
> Do you know If I'm missing anything obvious that prevents the cookie
> retrieval to work?
>=20
> Thanks!,
> --=20
>=20
> V=EDctor Gil Sep=FAlveda
> E. Informatica - FIB - UPC
>=20
> _______________________________________________
> Mod_python mailing list
> [email protected]
> http://mailman.modpython.org/mailman/listinfo/mod_python