[REBOL] Re: CGI session variables like in PHP
From: SunandaDH:aol at: 7-Oct-2003 16:18
Carlos:
> I'm just thinking about wich is the best way to handle
> persistent words between HTML pages such as PHP does
> with its session variables.
I don't know the *best* way, as HTTP is inherently stateless. But here are
two ideas:
1. If you have identified users (by setting a cookie), use the cookie as a
key to an object that holds the session variables for that user. This is what
REBOL.org does, and it seems to work.
2. If you don't have cookies, you can't identify users by IP address (those
with dynamic IP addresses may give you a different value for every click of
enter). So you are pretty much reduced to having a hidden field on every page.
Use that as the key to the session variables object.
This second method will leave you a lot of discarded session-variable objects
as there is no way a user can "log off". You'll want to run an occasional
cleanup routine to discard these.
To generate a unique key for a session or cookie, experiment with:
session-key: copy ""
error? try [append session-key to-tuple system/options/cgi/remote-addr]
append session-key now/precise
session-key: checksum/secure session-key
(the error? is for when you are testing locally, and may not be a cgi
program. remote-addr is the IP address).
Sunanda.