clickit has asked for the wisdom of the Perl Monks concerning the following question:

I set up the following script to insert the shopping cart number on user's PC so that the shopping cart can remember the items placed in the user's shopping cart.
($Second, $Minute, $Hour, $DayOfMonth, $Month, $Year, $WeekDay, $DayOf +Year, $IsDST) = gmtime(time + 10800); @Mth = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec'); @Day = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); $SetYear = 1900 + $Year; $SetDay = $Day[$WeekDay]; $SetMonth = $Mth[$Month]; $expdate = $SetDay.', '.sprintf('%02d', $DayOfMonth).'-'.$SetMonth.'-' +.$SetYear.' '.sprintf('%02d:%02d:%02d', $Hour, $Minute, $Second).' GM +T'; $file = "cart.html"; @BODY=(); open(FILE, "$file"); @BODY=<FILE>; close(FILE); $NOS=$#BODY; print "Content-type: text/html\n"; &SetCookieExpDate("$expdate"); &SetCookiePath('/'); &SetCookieDomain('.clickitpro.com'); &SetCookies("$sid-cart", "$cartnum"); print "\n"; for ($i=0;$i<=$NOS;$i++) { $_ = $BODY[$i]; print "$_"; }
I tested it on my Windows PC and I was able to add multiple items to my shopping cart even after leaving the shopping cart for more than an hour. However, my client complained that many of her shoppers could not add multiple items to the shopping cart when they are using windows PC. However, she claimed that the cookies worked properly with MAC. I am totally lost here! Can someone help me, please? What could have caused the problems? Thank you!

Replies are listed 'Best First'.
Re: Why cookies do not work on some users' windows PC?
by davidrw (Prior) on Feb 26, 2006 at 14:45 UTC
    I suspect it's a browser issue, not a platform issue .. What browsers are they using on the PC's? on the MAC? Most importantly, are cookies enable on the PC browsers?? is your site blacklisted in their browser? Might be useful to google for "cookie check" and have them try one of those sites, to see if it's all cookie sites or just yours ..

    Some code comments:
    • Make sure you do use strict; and use warnings;
    • The date code (also check out modules like Date::Calc and DateTime) can simply be:
      use POSIX qw/strftime/; my $expdate = strftime('%a, %d-%b-%Y %H:%M:%S GMT+', gmtime(time + 108 +00) );
    • That for can simply be replaced with print @body;
      If you wanted to keep the loop cause you need the index for something, more perlish way is:
      foreach my $i ( 0 .. $#body ){ print "$i) $body[$i]"; }
      Or with loop, but without index:
      foreach my $s ( @body ){ print $s; }
    • no need to keep a $NOS variable -- just use $#body (for last element) or scalar(@body) (for count) when needed
    • what do your SetCookieFOO functions look like?
Re: Why cookies do not work on some users' windows PC?
by spiritway (Vicar) on Feb 26, 2006 at 23:25 UTC

    As [id://davidrw] notes, this sounds like a browser issue. It's not clear to me what you are using to save cookies - did you roll your own, or are you using a module? You might check out documentation for HTTP::Cookies::Microsoft and HTTP::Cookies::Netscape. Internet Explorer preserves cookies as individual files. Netscape keeps them in a single file (or cookie jar). What works for one may fail for the other.

    You might consider downloading and installing all of the popular browsers, and testing your program on each one. Apparently it works for you with your default browser. Try installing IE, Opera, Netscape, and Firefox, at least.

    You may need to test for what browser is being used, and call different code depending on what you discover.

      It is certainly a browser issue. Your answer has been most helpful. I will try the two modules. Thank you!