#BEGIN .htaccess #I have tried setting it as a Handler # -> All this did was cause the SSI # to not work. Action set-cart /cart/setcart.pl AddHandler setcart .shtml # I have also tried using mod-rewrite, # sending all .shtml requests to the # script 1st, then back to their original # destination. #RewriteEngine on # pre-process all requests with setcart.pl # RewriteCond %{ENV: REQ_URL} !$1 [NC] #RewriteRule ^(.*)$ /cart/setcart.pl [E=REQ_URL:$1,NS,L] # (Ofcourse I tried one at a time, hence # the commented-out Rewrite. #END .htaccess #BEGIN setcart.pl #!/usr/bin/perl -w # perl error reporting switches # -c = check the code for syntax errors # -w = "use warnings" and tells the interpreter to produce useful diagnostics # -T = "taint mode" which adds security internal to Perl # use strict; use vars qw($script_name $query $template $raw_cookie $totalvalue $itemt $subt $grandt $ouncest $shippingt @Cookie &CookieCheck &GetCookies &SetCookies); use CGI qw/-no_xhtml :standard/; use CGI::Cookie; use CGI::Carp qw(fatalsToBrowser); $CGI::POST_MAX=1024 * 100; # max 100K posts $CGI::DISABLE_UPLOADS = 1; # no uploads ############### COOKIE STRATEGY ######################### # 4 cookies manage cart info # "total" is the main cookie set right away, it has # "itemt" = number of total items in cart # "subt" = total cost minus shipping cost and tax # "grandt" = total cost plus shipping cost and tax # "ouncest" = total shipping weight in ounces # "shippingt" = total cost of shipping for order # "itemprice" holds the numerical data of the order # "itemnum" = the item number itself # "itemqty" = the quantity requested for the item # "baseprice" = the retail price of the smallest item in its set # "upsizeamt" = the cost added ontop the base price for larger items # "details" holds the descriptive information for a particular item # "isize" = the requested item size # "icolor" = the requested item color # "istyle" = the requested item style # "iounces" = the shipping weight for item in ounces # "itemtitle" holds the descriptive title of the requested items # "ititle" = the descriptive title of the requested items # Each cookie will have it's data packed into a semicolon seperated scalar # Note: I will later need to add handling for maximum cookie length to branch # into multiple cookies if there is a very large order. ######################################################### ############### SCRIPT STARTS HERE ###################### $script_name = "setcart.pl"; $query = new CGI; &CookieCheck; sub CookieCheck { # check for default cookie "total" if (GetCookies('total')) { # if total exists, get it's current values for "itemt" and "grandt" my $rawvalue = pop(@Cookie); ($itemt, $subt, $grandt, $ouncest, $shippingt) = split(/;/, $rawvalue); # This goes with the Rewrite attempt #print $query->redirect(-uri=>'$ENV{'REQ_URL'}'), "\n\n"; } else { # Set total to default zero values # In this order: itemt, subt, grandt, ouncest, shippingt $totalvalue = "0;0.00;0.00;0;0.00;"; SetCookies('total',$totalvalue); # Now do a check to make sure the cookie was set if (GetCookies('total')) { # if total exists, get it's current values for "itemt" and "grandt" my $rawvalue = pop(@Cookie); ($itemt, $subt, $grandt, $ouncest, $shippingt) = split(/;/, $rawvalue); # This goes with the Rewrite attempt #print $query->redirect(-uri=>'$ENV{'REQ_URL'}'), "\n\n"; } else { # Other wise redirect to "Cookies are Required" page print $query->redirect(-uri=>/cookiereq.html'), "\n\n"; } } } sub SetCookies { my (%input) = @_; while( my($name,$value) = each %input ) { my $c = CGI->cookie ( -name => $name, -value => $value); print "Set-Cookie: ", $c, "\n"; } } sub GetCookies { my @cookies = @_; my $exists = 0; foreach my $name (@cookies) { if (defined CGI->cookie($name)) { my $value = CGI->cookie($name); push(@Cookie,$name,$value); $exists = 1 if $value; } } return $exists; }