3 # This is a sample script that may be used to create domain specific
4 # unique ID's rather than using UUID. In a typical scenario, this HTID
5 # generator would reside in the same domain as the target server, so
6 # that it could be used by any clients of the server. While use of UUID
7 # as a unique identifier is perfectly fine, use of a remote generator
8 # gives additional benefits, such as the ability to collect metrics on
11 print "Content-type:text/html\n\n";
13 $htid = $ENV{'REMOTE_ADDR'};
15 open(IN
,"counts.txt") or dienice
("Can't open counts.txt for writing: $!");
17 flock(IN
,2); # lock the file
18 seek(IN
,0,0); # rewind it to the beginning
20 $oldtimestamp = <IN
>; # read only the first line.
21 $save_time = $oldtimestamp;
28 if ($oldtimestamp == $timestamp)
30 open (IN2
, "sec_id.txt") or
31 dienice
("Can't open sec_id.txt for writing: $!");
36 $secondary_id = <IN2
>;
38 # increment the secondary id
49 open(OUT2
,">sec_id.txt") or
50 dienice
("Can't open outdata.txt for writing: $!");
52 flock(OUT2
,2); # lock the file
53 seek(OUT2
,0,0); # rewind it to the beginning
55 print OUT2
"$secondary_id";
60 #save the timestamp for next time
61 $oldtimestamp = $timestamp;
64 open(OUT
,">counts.txt") or dienice
("Can't open outdata.txt for writing: $!");
66 flock(OUT
,2); # lock the file
67 seek(OUT
,0,0); # rewind it to the beginning
68 print OUT
"$oldtimestamp\n";
72 $result_string = join (".$timestamp", $htid, ".$secondary_id");