Mailing List Archive



Back to the month index Back to the list index

Bryan A. Pendleton (bp@beau37.wustl.edu)
Mon, 7 Apr 1997 17:52:37 -0500 (CDT)


Date: Mon, 7 Apr 1997 17:52:37 -0500 (CDT)
From: "Bryan A. Pendleton" <bp@beau37.wustl.edu>
Subject: [mSQL] Alright already...
Message-Id: <Pine.LNX.3.93.970407172927.16972A-100000@bpdomain.wustl.edu>

Ok, several people have responded with interest to my
cookie/user-tracking related postings... it took me until now, but I have
some of the stuff ready to show.

On my website, at http://bpdomain.wustl.edu/msql/, I have posted some of
the code that I use.... the most interesting file is the second one, my
www.lite file. This defines several functions which can be used to get/set
cookies on a given web page.... More information on Cookies an be found on
the net... if you have trouble finding it, I could post a URL later, but I
don't have my favorite one handy right now (it's on Netscape's server,
the original proposal for cookie stuff).

At any rate, here's generally how to use the cookie code:

   getCookie() should be called with the HTTP_COOKIE, and the name of the
                cookie you want to get. For instance, on my website, under
                /mp3/, almost every file does a
                $num=getCookie($HTTP_COOKIE,"MP3NUM") at the top to
                determine if the user has been there before. If $num
                gets assigned a null string, then a new number is
                found (I use a _seq on my Users database for that)
                and assigned via a netCookie call.

   newCookie() call this from the extreme top of your script, as it must
                be called so that it is output inside the <head>
                tags of your script. It makes use of the <meta> tag
                to put cookie information in the header of the file.
                If you're writing cookie code that runs pure CGI
                rather than through w3-msql, it would make more sense
                to simply output the Set-Cookie text that netCookie()
                generates inside the header of that script.

So, what do I do with all of this? If a user comes in who's cookie is not
set, a user number is found (from the _seq) and set to the value of the
new number. From then on, it is as easy as creating a database which
stores whatever information you want to remember about the user, using the
user's assigned cookie number as the unique index key. As can be seen from
my head(), every page of my mp3 site will check if the user has a number
yet, assign one to him/her, and update the User db to reflect some status
information about that user's session.

Well, that's enough speel for now. I don't promise that any of my code is
clean or efficient... and I'm open to suggestions in ways to improve it.
If any of you decide to use my code or precedent in your sites, all I ask
is that you let me know, and, if possible, let me peak at yours in action
as well.

                                                ((((((BP))))))
"The root of all knowledge lies within, but knowledge is useless unless it
is collected and shared."

--------------------------------------------------------------------------
To remove yourself from the Mini SQL mailing list send a message containing
"unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing
"info msql-list" to majordomo@bunyip.com for info on monthly archives of
the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!