#!/usr/bin/perl # Flush buffer $| = 1; print "Content-type: text/html\n\n"; $cwd = $ENV{'SCRIPT_FILENAME'} || $0; $cwd =~ s/\\/\//g; my(@cwds) = split(/\//,$cwd); pop(@cwds); $cwd = join("/",@cwds); my($cart_id) = ""; my(%cookies) = &get_cookies; if($cookie{'cookies_enabled'} eq "yes"){ if($cookies{'cart_id'} ne ""){ $cart_id = $cookies{'cart_id'}; } } elsif($cookies{'cart_id'} ne ""){ $cart_id = $cookies{'cart_id'}; } else{ $cart_id = &get_cart_id_from_address_log("$cwd/user_carts"); } print $cart_id; # Cookies -------------------------------------------------------- sub get_cookies { my($chip, $val); foreach (split(/; /, $ENV{'HTTP_COOKIE'})) { s/\+/ /g; ($chip, $val) = split(/=/,$_,2); # splits on the first =. $chip =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; $val =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; $cookies{$chip} .= "\1" if (defined($cookies{$chip})); $cookies{$chip} .= $val; } return(%cookies); } # IP Address Log ---------------------------------------------------- sub get_cart_id_from_address_log { my($cart_path) = @_; my($remote_host) = $ENV{'REMOTE_ADDR'} || $ENV{'REMOTE_HOST'}; my($cart_id) = ""; $ip_log = "$cart_path/ip\.$remote_host"; if(-e "$ip_log"){ open (ADDRESS_LOG,"$ip_log"); $cart_id = (); close (ADDRESS_LOG); $cart_id =~ s/\s//; } return ($cart_id); } # end get_cart_id_from_address_log 1;