sub unique_id {
use Digest::MD5;
my $md5 = new Digest::MD5;
my $remote = $ENV{REMOTE_ADDR} . $ENV{REMOTE_PORT};
my $id = $md5->md5_base64(
time, # current time
$$, # process id
$remote); # host and port
$id =~ tr|+/=|-_.|; # make the result URL friendly
return $id;
}
<form action="script.cgi" method="POST">
<input type="hidden" name="id"
value="107-5364765-8343766">
.
.
</form>
start => menu catalog => catalog/POST | menu cart => menu checkout => thanks/POST | menu thanks => /GET request sent via GET /POST request sent via POST
menu == catalog/GET | cart/GET | checkout/GET
sub catalog {
my ($q, $id) = @_;
if ($q->request_method eq "POST") {
save_state($q);
}
print header($q, "Video Catalog"),
.
.
$q->hidden(
-name => "id",
-default => $id,
-override => 1
),
$q->hidden(
-name => "action",
-default => "catalog",
-override => 1
),
$q->end_form,
footer($q, $id);
}
my $q = new CGI;
my $action = $q->param("action") || "start";
my $id = get_id($q);
if ($action eq "start") {
start($q, $id);
} elsif ($action eq "catalog") {
catalog($q, $id);
} elsif ($action eq "cart") {
cart($q, $id);
} elsif ($action eq "checkout") {
checkout($q, $id);
} elsif ($action eq "thanks") {
thanks($q, $id);
}
http://www.amazon.com/exec/obidos/subst/home/home.html/ 107-5364765-8343766
<p><b><font face=verdana,arial,helvetica size=-1> <a href=/exec/obidos/tg/new-for-you/pym/home/-/0/ref=pd_gw_cp_pym/107-5364765-8343766>Quick Picks</a></font></b> <br> <a href=/exec/obidos/ASIN/059600012X/ref=pd_gw_cp_1/107-5364765-8343766> <img src="http://images.amazon.com/images/P/059600012X.01.20TLZZZZ.gif" width=77 height=97 vspace=3 hspace=7 align=left border=0></a> <a href=/exec/obidos/ASIN/059600012X/ref=pd_gw_cp_1/107-5364765-8343766> <img src="http://g-images.amazon.com/images/G/01/icons/small-blue-books-icon.gif" width=18 height=18 border=0 alt=Icon > </a> <font face=verdana,arial,helvetica size=-1> <a href=/exec/obidos/ASIN/059600012X/ref=pd_gw_cp_1/107-5364765-8343766> Managing Imap </a> <br><font face=verdana,arial,helvetica size=-1>by Dianna Mullet, Kevin Mullet</font> </font> <p> <A NAME="059600012x7500"></A> Plain old Post Office Protocol (POP) is fine for just logging in and grabbing your e-mail from a dial-up service, but more elaborate mail-management and messaging solutions require a more capable protocol. The Internet Mail Access Protocol (IMAP) fits the bill by allowing you to pull off all sorts of mail-management tricks. With IMAP, a single user... <a href=/exec/obidos/ASIN/059600012X/ref=pd_gw_cp_1/107-5364765-8343766> <font size=-1>Read more</font></a>
sub footer {
my (@q, $id) = @_;
my $catalog_link = $q->a(
{ -href => "$url?action=catalog&id=$id" },
"View Catalog"
);
my $cart_link = $q->a(
{ -href => "$url?action=cart&id=$id" },
"Show Current Cart"
);
my $checkout_link = $q->a(
{ -href => "$url?action=checkout&id=$id" },
"Checkout"
);
return $q->hr,
$q->p("[ $catalog_link | $cart_link | $checkout_link ]"),
$q->end_html;
}
Set-Cookie: id=107-5364765-8343766;
domain=.amazon.com;
path=/exec/obidos;
expires: Web, 28-Feb-2001, 12:00:00 GMT
my $cookie = $q->cookie(
-name => "id",
-value => "107-5364765-8343766",
-domain => ".amazon.com",
-expires => "+1d");
Cookie: id=107-5364765-8343766
name1=value1;name2=value2;...;nameN=valueN
my $id = $q->cookie("id");
if ($ENV{HTTP_COOKIE}) {
@cookies = split(/;/, $ENV{HTTP_COOKIE});
foreach $cookie (@cookies) {
($name, $value) = split(/=/, $cookie);
$crumbs{$name} = $value;
}
}
sub save_state {
my $q = shif;
my $cart = cart_filename($id);
# code left out to deal with denial
# of service attacks (see book)
open FILE, ">$cart" ||
die "cannot write to $cart";
$q->save(\*FILE);
close FILE;
}