On Wed, 22 Dec 1999 john_pallozzi@itworld.com wrote:
> Does anyone know if mSQL can set and/or read a cookie, and if it can how
> would you do it?
Here is a post Bambi sent last Fegruary. I don't use cookies, so
I haven't tested any of what he suggests.
Glenn
--------------------------------------------------------------------------
Date: Tue, 16 Feb 1999 23:21:24 -0500 (EST)
From: "David J. Hughes" <bambi@Hughes.com.au>
To: Multiple recipients of list <msql-list@services.bunyip.com>
Subject: Cookies and w3-msql
To help out Bryan Bowman <bryan@four-site.net> with getting a handle on
cookies, I put together an example script. It may help some other people
on the list as well. I've included it below.
All it does is keep 2 values in cookies. One is a counter that is
incremented on each page load. The other is a text string the is extended
on each page load.
Note that all the cookie handling code is at the top of the script (not
even a blank line before the <! tags ) as it _must_ be done before
anything is sent to the browser. On the first output, w3-msql will send
the headers so they must be set in the initial bit of the script.
Bambi
..
------------------------------- cookie.msql ----------------------------
<!
/*
** Grab the cookies from the CGI environment and extract the
** counter value. If it exists, increment it. If it doesn't
** set it to 1
*/
$cookieLine = $HTTP_COOKIE;
$cookies = split($cookieLine, ";");
$loop = 0;
while($loop < # $cookies)
{
if ($cookies[$loop] =~ "counter=.*")
{
$count = substr($cookies[$loop],"counter=(.*)","$1");
}
if ($cookies[$loop] =~ "string=.*")
{
$string = substr($cookies[$loop],"string=(.*)","$1");
}
$loop++;
}
if ($count == "")
{
$count = 1;
}
else
{
$count = (int)$count + 1;
}
if ($string == "" )
{
$string = "A";
}
else
{
$string = $string + "A";
}
addHttpHeader("Set-Cookie: counter=$count; path=/");
addHttpHeader("Set-Cookie: string=$string; path=/");
>
<HEAD>
<TITLE>Cookie Example</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
Cookie set to $count<P>
String set to '$string'<P>
</BODY>
-------------------------------------------------------------------------
To unsubscribe, go to http://www.Hughes.com.au/extras/email/
This archive was generated by hypermail 2b30 : Mon Mar 04 2002 - 09:04:04 EST