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 <BR>\n" append html "Password: $password <BR>\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" ] <FORM action=/login method=post> <table> <tr> <td>Username</td> <td><input name=username value="[Doc_Cookie username]"></td> </tr> <tr> <td>Password</td> <td><input name=password></td> </tr> <tr> <td><input type=submit></td> </tr> </table> </FORM> </HTML>
2002-01-29 Acacio Cruz
Wanted examples
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.