Here is an example script showing how to create and use cookies:
#!/bin/sh string=? ; exec /usr/local/plt/bin/mzscheme -r $0 "$@" (read-case-sensitive #t) (current-library-collection-paths (cons "/home/kfisler/CS2135/collects/" (current-library-collection-paths))) (require-library "cgi.ss" "2135net") (let ([bindings (append (get-bindings) (get-cookies))]) (generate-html-output/cookies "Short Order" (list (make-cookie "pizzastyle" "thin" "Wednesday, 3-Oct-01 23:12:40 GMT" "/~kfisler/" #f #f)) (list (format "~a ordered a ~a pizza ~n" (extract-first-binding 'Cust_Name bindings) (extract-first-binding 'pizzastyle bindings))) ))
To get the cookies support, you must include the lines from read-case-sensitive through require-library at the top of your script.
In this version, we call generate-html-output/cookies to create the HTML output. This takes an extra argument over the generate-html-output used in the sample solution. That extra argument (the second) is a list of cookies that should be stored when the script is run.
Here is the data definition for cookies:
A cookie is a (make-cookie string string (string or #f) (string or #f) (string or #f) boolean) (define-struct cookie (name value expires path domain secure)) ;; Constraints: * name must not contain the characters '=' or ';' ;; * value must not contain the character ';' ;; * expires must be of the format ;; "Wdy, DD-Mon-YYYY HH:MM:SS GMT" ;; * path must not contain the character ';' ;; * domain must not contain the character ';'
See the cookies documentation linked to on the project page for a description of these fields.
The get-cookies function extracts all the bindings that came from cookies. Use extract-first-binding to extract the value that was stored with a cookie.