#!/usr/local/bin/perl
#Sets the cookies the hard way
#file: cookie.pl

require '/home/scsfac/downeyt/scripts/parse-lib.pl';

%query=&get_query;
%cookie=&get_cookie;

$gmt=&time_gmt;
$new_gmt=&time_gmt(10);

#unload the cookie
if (scalar %cookie)
{
    $first = $cookie{'first'};
    $last = $cookie{'last'};
    $restricted_cookie = $cookie{'restricted_cookie'};
    $timed_cookie = $cookie{'timed_cookie'};
}

#unload the query string. if non-empty, then set the cookie
if ($query{'restricted_cookie'})
{
    $restricted_cookie=$query{'restricted_cookie'};
    print "Set-cookie: restricted_cookie=$query{'restricted_cookie'};";
    print "path=/scripts/cookie.get.restricted.pl\n";
}
if ($query{'timed_cookie'})
{
    $timed_cookie=$query{'timed_cookie'};
    print "Set-cookie: timed_cookie=",escape("$query{'timed_cookie'} $new_gmt"),";";
    print "expires=$new_gmt; path=/\n";
}
if ($query{'first'})
{
    $first=$query{'first'};
    print "Set-cookie: first=$query{'first'};path=/\n";
}
if ($query{'last'})
{
    $last=$query{'last'};
    print "Set-cookie: last=$query{'last'}; path=/\n";
}
print "Content-type: text/html\n\n";

print <<BODY;
<html>
<head>
<title>Test Cookie</title>
</head>
<body>
<form method=post>
<p>First: <input type="text" name="first" value="$first">
<p>Last: <input type="text" name="last" value="$last">
<p>The resticted cookie can only be viewed from a specific URL. Use the path parameter to control which path can see the cookie.
<br>Restricted Cookie: <input type="text" name="restricted_cookie" value="$restricted_cookie">
<p>The timed cookie will expire after 30 seconds. Use the expires parameter to control when the cookie is destroyed.<br>
Timed Cookie: <input type="text" name="timed_cookie" value="$timed_cookie">
<input type="submit">
</form>
</html>
BODY
    ;





