in reply to Re^3: Question regarding CGI and cookies
in thread Question regarding CGI and cookies
1. Check to see if there is a previously created COOKIE FILE. If so, put the items stored there in @purchases, otherwise leave @purchases empty.
2. Add the current purchase to @purchases.
3. Create a new COOKIE VARIABLE, $C_records, and store the value of @purchases there.
4. Print the new cookie variable as a COOKIE HEADER.
5. When the browser reads the COOKIE HEADER, it will create a new COOKIE FILE. This file will either replace the old previously created cookie file if it exists, or will be created as a completely new file.
Why should you check for a pre-existing COOKIE FILE before creating a new COOKIE VARIABLE? Because your script has no way of knowing whether this is the first item the user is purchasing or the tenth item. If it is the first item, checking for the COOKIE FILE will simply not find anything and the new COOKIE VARIABLE will be created entirely from the user's current purchases. If it is the second, or third, or tentch item the user is purchasing, checking for the COOKIE FILE will find the previous purchases and add them to the current purchase so that when you create a new COOKIE VARIABLE, that variable will contain both current and previous purchases.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Question regarding CGI and cookies
by Anonymous Monk on Nov 11, 2004 at 23:21 UTC |