#!/usr/local/bin/perl
#Sets the cookies, uses the CGI module
#file: cookie.pl

use CGI;

$query=new CGI;

%data=$query->cookie('data');

%data=&set_data('first');
%data=&set_data('last');
%data=&set_data('restricted_cookie');

if (scalar %data)
{
    $cookie = $query->cookie(-name=>'data', -value=>\%data);
    print $query->header(-cookie=>$cookie);
} else {
    print $query->header;
}

print <<BODY;
<html>
<head>
<title>Test Cookie</title>
</head>
<body>
<form>
<p>First: <input type="text" name="first" value="$data{'first'}">
<p>Last: <input type="text" name="last" value="$data{'last'}">
<p>Restricted Cookie: <input type="text" name="restricted_cookie" value="$data{'restricted_cookie'}">
<input type="submit">
</form>
</body>
</html>
BODY

    ;

sub set_data
{
    local($name)=@_;

    if ($query->param(-name=>$name))
    {
	$data{$name}=$query->param(-name=>$name);
	$key{$name}=$name;
    }
    return %data;
}

