Patrick Chan's Cookie Solution

greenspun.com : LUSENET : S-Mart Shopping Cart : One Thread

I may be 2 years too late to contact Patrick since his last post is around 2000-2001. I'm in anxious pursuit of the answer that he has for enabling cookies in S-MART. Has he shared it with any of you and if so would you consider sharing it with me via E-MAIL or this board?

Thanks!

Don Thompson GoGoMag.com

-- Don Thompson (brtb@brtb.com), November 20, 2002

Answers

This was posted in an earlier thread here and seems to work great. Very easy to add. Thanks BP!

After a long debate on using REMOTE_HOST or REMOTE_ADDR, neither of which completely fixes the aol problems, I've implemented the use of cookies into the script. For all of you that are wondering, here's how you do it: Near the top of the script, add the following line: require 'cookie.lib'; (I put this line right below my require smart.cfg line)

This tells the script to use the cookie libraries. The file cookie.lib is readily available on the internet. Search for it and you should be able to find it by file name, otherwise send me a message and I'll drop you a copy.

Next, I just added the following at the bottom of the SUB GET_HOST section:

# Here is the START of the cookie section # If there already is a count cookie, proceed without setting a new one. if (&GetCookies ('userid')) { # set cookie content $cookiecontent = $Cookies {'userid'}; }

# Otherwise, if the use didn't already have a cookie, give them one! else { $useridnum = time() . "-" . $$; # Set a new cookie. &SetCookies ('userid', $useridnum); $cookiecontent = $useridnum; }

$reffile = "$tmpdir$delim$storename-$cookiecontent";

# This is the END of the cookie section

Just cut and paste that into the script and you will be up and running with cookies - since the $reffile is set in the sub get_host section which runs before anything else runs, the entire script is running using that userid and never even needs to look at the remote_host or remote_addr. Took a few hours to figure everything out and learn how cookies work but it was well worth the time.

The userid was generated based on the same system how the script can automatically create an order id number.

Hope this helps some of you out who have been struggling with the AOL proxy server issue! By cutting and pasting the above text into your script you should be up and running with cookies in a matter of minutes!

Take care

-BP

-- BP (bppilot@aol.com), August 04, 1999

-- Don Thompson (gogomagazine@aol.com), December 01, 2002.


Moderation questions? read the FAQ