This page will try to collect code examples to ease the beginners to fully exploit one of Tcl's pearls, [TclHTTPD], a pure-Tcl HTTPD server.
----
Added to link to all [Cookies] related pages.
----
'''Setting a Cookie'''
To set a cookie, first use Doc_SetCookie. The following is an example of a function setting a cookie:
Direct_Url /login login
proc login { {username none} {password none} } {
set expire [clock format [expr {[clock seconds] + 3600}] \
-format "%A, %d-%b-%Y %H:%M:%S GMT" -gmt 1]
Doc_SetCookie -name username -value $username -expires $expire \
-path {/} -domain {yourdomain.com}
# Just output parameters; for debugging
set html [html::head "Login" ]
append html "Username: $username
\n"
append html "Password: $password
\n"
return $html
}
'''NOTE''': Current problem is that the cookies added this way don't seem to last long, even without expiration set. If the browser is restarted, the cookie goes away. Seen in both IE & Netscape. Comments welcomed.
2002-01-29 [Acacio Cruz]
----
'''Retrieving a Cookie'''
To retrieve a saved cookie, use Doc_Cookie.
The following is an example of simple .tml form that can be used as a login form:
[ Doc_Dynamic
html::head "Login form" ]