I have this cgi perl script that sets a cookie and then checks to see if the cookie exists and prints out the value back to the browser (which all works fine). In my code below I would like to create a unique user id. I'm not passing any form or query string values to this cgi-bin script (the purpose of this script is not to do that), and I'm not sure what method to use to generate a unique identifier. I want the script to create the identifer and then initialize the cookie the next time the user comes back to the site or does a reload and then I will do some processing, like redirect the user to another site. Here is my code.
#!/opt/bin/perl
use CGI ':standard';
$query = new CGI();
$sweet = $query->cookie(-name=>'answers');#check for a cookie
#Get current Time
$current_time = localtime;
#does cookie exist
if ($sweet) {
print "Content-type: text/html\n\n";
#create html page info
print $query->start_html(-title=>"Session"),
$query->h1("cookie exists $sweet<BR>"),
$query->p("The current time is $current_time<BR>");
end_html;
#cookie doesn't exist, set one and send it to the browser
}else{
$cookie = $query->cookie(-name=>'answers',
-value=>'Register',
-expires=>'+1h',
-path=>'/cgi-bin/');
print $query->header(-type=>'text/html', -cookie=>$cookie);
print "<B>Cookie Set <b>";
}
exit;
edited: Thu Mar 13 15:56:05 2003
by jeffa - code tags