Setting the domain with setCookie and **kw?
To show I am trying. ;) I found this old post below that still leaves me with some Q's. How do you format setCookie to control the domain that is referenced? example: setCookie auto-sets the subfolder address, www.domain.com/sub1/sub2 BUT I want to set the cookie for the root URL without the sub-domain (www). example: .domain.com is what I want to write in the cookie to share across sub-domains. What is **kw? in setCookie(name, value, **kw) It is referenced many times in Appendix B: Zope Book. Thanks for the help! -Trevor ////old post
Zope reference gives such a header for this method: setCookie(name, value, **kw), but the **kw argument is not described. What it is?
setCookie is a convenience function to construct the response header. As this rfc header can have some additional attributes, they can be given to the setCookie() method too. Useful options are: - expires this should be set to a date/time in the Future, where the cookie is to be expired (hence the name ;) The format is Wdy, DD-Mon-YYYY HH:MM:SS GMT, so you might want to use DateTime().strftime() here. - path At least if you set "expires" you should send a path (minimum /) from which the cookie should work. Otherwise it gets not stored for old Netscape versions and a few proxies (Novell Bordermanager[tm] is known to behave like this) - domain The domain for which the cookie has to be send for each request. This defaults to the exact hostname of the server. - secure you can specify this with secure='' to get the browser sending it only over ssl. HTH Tino Wildenhain
At 06:05 6-9-01, you wrote:
To show I am trying. ;) I found this old post below that still leaves me with some Q's.
How do you format setCookie to control the domain that is referenced? example: setCookie auto-sets the subfolder address, www.domain.com/sub1/sub2 BUT I want to set the cookie for the root URL without the sub-domain (www). example: .domain.com is what I want to write in the cookie to share across sub-domains.
What is **kw? in setCookie(name, value, **kw) It is referenced many times in Appendix B: Zope Book.
Thanks for the help! -Trevor
Hello cookiemonster Trevor, when you see a function x(arg1, *args) it means that x really NEEDS the first argument arg1 and CAN handle a bunch of extra arguments following arg1. The size of the bunch ( a tuple in Python-speach) is arbitrary, i.e. x(arg1, arg2, arg3) is just as well as is x(arg1, arg2, arg3, arg4, arg5) or x(arg1). Of course arg1 must not be a part of this bunch of extra arguments. When you see a function y(arg1, **kw) it means that y expects a bunch of keyword arguments (a dictionary in Python-speach) of the form keyword=''value'. The size of the bunch is arbitrary and again, arg1 must not be a one of the keywords in this bunch of extra keyword arguments. E.g. y(arg1, kw1='foo', kw2='bar', kw3='baz') See also sections 4.6 and 4.7 of the python tutorial http://www.python.org/doc/current/tut/tut.html for the original explanation. Hope this helps, Roger
On Thu, Sep 06, 2001 at 12:05:51AM -0400, Trevor Toenjes wrote:
How do you format setCookie to control the domain that is referenced? example: setCookie auto-sets the subfolder address, www.domain.com/sub1/sub2 BUT I want to set the cookie for the root URL without the sub-domain (www). example: .domain.com is what I want to write in the cookie to share across sub-domains.
What is **kw? in setCookie(name, value, **kw) It is referenced many times in Appendix B: Zope Book.
setCookie("region", "moscow", expires="Thu, 21 Dec 1967 23:45:00", path="/foo", domain=".bar.com") expires gives the date/time of cookie expiration - the time a browser will forget it and clear from its cookies file; without "expires" the cookie will lasts only one session (while browser is up and running); path is an URL part that must match a request; without "path" browser assumes the path of the current request; domain is... well, domain :) In .com, .org, .gov, .net, .edu it is possible to set the 2nd-level domain (.ucsd.edu), in other TLDs you are not allowed to set 2nd-level domains; use 3rd-level domains only (.foo.bar.mx). Without "domain" broswer assumes current server's host (host, not domain). Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
Oleg, Thanks for the great explanation and correcting my rhetoric(so my questions are clearer next time). Everything is writing the cookie correctly, but now I cant get other paths to read it.
From Oleg- setCookie("region", "moscow", expires="Thu, 21 Dec 1967 23:45:00", path="/foo",domain=".bar.com")
How do I control the PATH to read a cookie? I am using <dtml-if "REQUEST.has_key('myCookie')> <dtml-var myCookie> located in www.bar.com/folder1/folder2 *This seems to check the current PATH only. How do you look in ".bar.com/foo"? I tried using <dtml-with foo> to no avail. I get {KeyError on myCookie} Can anyone get me on the ... uh-hum, right PATH? :) Thanks, Trevor
On Thu, Sep 06, 2001 at 12:34:34PM -0400, Trevor Toenjes wrote:
How do I control the PATH to read a cookie?
I do not understand the question.
I am using <dtml-if "REQUEST.has_key('myCookie')> <dtml-var myCookie> located in www.bar.com/folder1/folder2
If you setCookie("region", "moscow", path="/foo", domain=".bar.com"), the browser will send the cookie along with every request that matches the path, in this domain. For example, request to http://www.bar.com/foo will set the cookie, as well as for http://foobar.bar.com/foo/bar, but the cookie will not be set for request http://www.bar.com/baz/foo Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
There might be a better way to do this, but I am attempting to do user tracking thru the site based on a GUID. My goal is true click-stream collection and analysis. Calling a setGUID method doesnt seem to work, and I dont know if it is cookies behavior or my code? if you come into the site thru /foo, one way works, Folder www.bar.com ###index_html <dtml-if "REQUEST.has_key('GUID')"> <dtml-var GUID> <dtml-else> <dtml-var setGUID> </dtml-if> ###dtml-method - setGUID <dtml-call "REQUEST.set('ts', ZopeTime())"> <dtml-call "REQUEST.set('uid_global',_.str(_.int(ts)))"> <dtml-call "RESPONSE.setCookie('GUID', uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')"> Folder www.bar.com/foo ###dtml-method <dtml-if "REQUEST.has_key('GUID')"> <dtml-var body_root> <dtml-else> <dtml-var setGUID> </dtml-if> <dtml-var GUID> <--! fails to render if this is the users first page, says Error:KeyError/GUID --> Thank you for the help, -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Oleg Broytmann Sent: Thursday, September 06, 2001 12:43 PM To: Zope@Zope. Org Subject: [Zope] Re: reading a cookie from another PATH??
On Thu, Sep 06, 2001 at 12:34:34PM -0400, Trevor Toenjes wrote:
How do I control the PATH to read a cookie?
I do not understand the question.
I am using <dtml-if "REQUEST.has_key('myCookie')> <dtml-var myCookie> located in www.bar.com/folder1/folder2
If you setCookie("region", "moscow", path="/foo", domain=".bar.com"), the browser will send the cookie along with every request that matches the path, in this domain. For example, request to http://www.bar.com/foo will set the cookie, as well as for http://foobar.bar.com/foo/bar, but the cookie will not be set for request http://www.bar.com/baz/foo
Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
This would probably make it work: ###dtml-method - setGUID <dtml-call "REQUEST.set('ts', ZopeTime())"> <dtml-call "REQUEST.set('uid_global',_.str(_.int(ts)))"> <dtml-call "REQUEST.set('GUID', uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')"> <dtml-call "RESPONSE.setCookie(REQUEST['GUID'])"> ----- Original Message ----- From: "Trevor Toenjes" <zope@toenjes.com> To: "Oleg Broytmann" <phd@phd.pp.ru>; "Zope@Zope. Org" <zope@zope.org>; "Roger Erens" <rlwm.erens@home.nl> Sent: Thursday, September 06, 2001 6:57 PM Subject: RE: [Zope] Re: reading a cookie from another PATH??
There might be a better way to do this, but I am attempting to do user tracking thru the site based on a GUID. My goal is true click-stream collection and analysis. Calling a setGUID method doesnt seem to work, and I dont know if it is cookies behavior or my code? if you come into the site thru /foo, one way works,
Folder www.bar.com ###index_html <dtml-if "REQUEST.has_key('GUID')"> <dtml-var GUID> <dtml-else> <dtml-var setGUID> </dtml-if>
###dtml-method - setGUID <dtml-call "REQUEST.set('ts', ZopeTime())"> <dtml-call "REQUEST.set('uid_global',_.str(_.int(ts)))"> <dtml-call "RESPONSE.setCookie('GUID', uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')">
Folder www.bar.com/foo ###dtml-method <dtml-if "REQUEST.has_key('GUID')"> <dtml-var body_root> <dtml-else> <dtml-var setGUID> </dtml-if> <dtml-var GUID> <--! fails to render if this is the users first page, says Error:KeyError/GUID -->
Thank you for the help, -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Oleg Broytmann Sent: Thursday, September 06, 2001 12:43 PM To: Zope@Zope. Org Subject: [Zope] Re: reading a cookie from another PATH??
On Thu, Sep 06, 2001 at 12:34:34PM -0400, Trevor Toenjes wrote:
How do I control the PATH to read a cookie?
I do not understand the question.
I am using <dtml-if "REQUEST.has_key('myCookie')> <dtml-var myCookie> located in www.bar.com/folder1/folder2
If you setCookie("region", "moscow", path="/foo", domain=".bar.com"), the browser will send the cookie along with every request that matches the path, in this domain. For example, request to http://www.bar.com/foo will set the cookie, as well as for http://foobar.bar.com/foo/bar, but the cookie will not be set for request http://www.bar.com/baz/foo
Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
This would probably make it work:
###dtml-method - setGUID <dtml-call "REQUEST.set('ts', ZopeTime())"> <dtml-call "REQUEST.set('uid_global',_.str(_.int(ts)))"> <dtml-call "REQUEST.set('GUID', uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')">
<dtml-call "RESPONSE.setCookie(REQUEST['GUID'])"> Chris, this is the error I get... Error Type: TypeError Error Value: setCookie() takes exactly 3 arguments (2 given) So I used the syntax below and get the same error that GUID doe snot exist? Is this an acqisition/namespace thing?
Is ... <dtml-call "RESPONSE.setCookie(REQUEST['GUID'],uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')"> the same thing as ... <dtml-call "REQUEST.set('GUID', uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')"> Thanks, -Trevor
Oops, I was totally wrong. Sorry! Try this instead: <dtml-call "REQUEST.set('GUID', ZopeTime().timeTime()"> <dtml-call "RESPONSE.setCookie('GUID', REQUEST['GUID'], expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')"> Or in a Python script: req = context.REQUEST guid = context.ZopeTime().timeTime() req.set('GUID', guid) req.RESPONSE.setCookie( 'GUID', guid, expires='Wed, 19 Feb 2020 14:28:00 GMT', domain='.bar.com', path='/' ) ----- Original Message ----- From: "Trevor Toenjes" <zope@toenjes.com> To: "Chris McDonough" <chrism@zope.com>; "Trevor Toenjes" <zope@toenjes.com>; "Oleg Broytmann" <phd@phd.pp.ru>; "Zope@Zope. Org" <zope@zope.org>; "Roger Erens" <rlwm.erens@home.nl> Sent: Thursday, September 06, 2001 9:39 PM Subject: RE: [Zope] Re: reading a cookie from another PATH??
This would probably make it work:
###dtml-method - setGUID <dtml-call "REQUEST.set('ts', ZopeTime())"> <dtml-call "REQUEST.set('uid_global',_.str(_.int(ts)))"> <dtml-call "REQUEST.set('GUID', uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')">
<dtml-call "RESPONSE.setCookie(REQUEST['GUID'])"> Chris, this is the error I get... Error Type: TypeError Error Value: setCookie() takes exactly 3 arguments (2 given) So I used the syntax below and get the same error that GUID doe snot exist? Is this an acqisition/namespace thing?
Is ...
<dtml-call "RESPONSE.setCookie(REQUEST['GUID'],uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')">
the same thing as ...
<dtml-call "REQUEST.set('GUID', uid_global, expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')">
Thanks, -Trevor
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
AWESOME! It works ... and I have no idea why? ;) 1. When do you use REQUEST vs. RESPONSE(REQUEST) ? 2. Is REQUEST['GUID'] the trick to place GUID in the namespace for every path? Thanks, -Trevor
Try this instead:
<dtml-call "REQUEST.set('GUID', ZopeTime().timeTime())"> <dtml-call "RESPONSE.setCookie('GUID',REQUEST['GUID'], expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')">
Or in a Python script:
req = context.REQUEST guid = context.ZopeTime().timeTime() req.set('GUID', guid) req.RESPONSE.setCookie( 'GUID', guid, expires='Wed, 19 Feb 2020 14:28:00 GMT', domain='.bar.com', path='/' )
Actions happen sequentially in a DTML script, so by doing REQUEST.set('GUID', ZopeTime().timeTime()), it allows other called elements later in the script to see the name "GUID" via the magic dtml name lookup rules. You use REQUEST when you want to refer to the request. You use RESPONSE when you want to refer to the response. I don't think that's what you're asking, but I didn't really understand the question so I'm making something up. ;-) From: "Trevor Toenjes" <zope@toenjes.com> To: "Chris McDonough" <chrism@zope.com>; "Trevor Toenjes" <zope@toenjes.com>; "Oleg Broytmann" <phd@phd.pp.ru>; "Zope@Zope. Org" <zope@zope.org>; "Roger Erens" <rlwm.erens@home.nl> Sent: Thursday, September 06, 2001 10:19 PM Subject: RE: [Zope] Re: reading a cookie from another PATH??
AWESOME! It works ... and I have no idea why? ;) 1. When do you use REQUEST vs. RESPONSE(REQUEST) ? 2. Is REQUEST['GUID'] the trick to place GUID in the namespace for every path? Thanks, -Trevor
Try this instead:
<dtml-call "REQUEST.set('GUID', ZopeTime().timeTime())"> <dtml-call "RESPONSE.setCookie('GUID',REQUEST['GUID'], expires='Wed, 19 Feb 2020 14:28:00 GMT',domain='.bar.com', path='/')">
Or in a Python script:
req = context.REQUEST guid = context.ZopeTime().timeTime() req.set('GUID', guid) req.RESPONSE.setCookie( 'GUID', guid, expires='Wed, 19 Feb 2020 14:28:00 GMT', domain='.bar.com', path='/' )
participants (4)
-
Chris McDonough -
Oleg Broytmann -
Roger Erens -
Trevor Toenjes