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" ]
Username
Password
2002-01-29 [Acacio Cruz] ---- '''Wanted examples''' * Session management * embedded tclhttpd use (skeleton, not bloated startup) see: [Starting Tclhttpd in a slave interpreter] 2002-01-29 [Acacio Cruz] ---- '''Doc_Cookie vs Httpd_Cookie''' Doc_Cookie sets cookies which will be returned (via Httpd_Cookie) if, and only if, the procedure setting them is either in a Direct domain, or called via DocTemplate (ie: a .tml file.) 2002-07-31 [CMcC] ---- '''File Upload''' This is a [File Upload example]. 2002-10-22 [Michael Hankinson] ---- '''Starter Code for easy image deployment''' [Image Server starter code for tclhttpd] 2002-10-24 art morel ---- [formkit] uses tclhttpd templates (tml pages) and metakit to store and retrieve web form information. ---- [Username/Password Database for Tclhttpd] is an example using the session module in Tclhttpd. It requires Metakit.