X-Git-Url: https://git.p6c8.net/selfforum.git/blobdiff_plain/504ff3f8ee5e277c2b1bf12a7a630098eaf55f0a..ba659b53059e637777865e646f0f2a6fb7f2988e:/selfforum-cgi/shared/Id.pm diff --git a/selfforum-cgi/shared/Id.pm b/selfforum-cgi/shared/Id.pm new file mode 100644 index 0000000..33c0c83 --- /dev/null +++ b/selfforum-cgi/shared/Id.pm @@ -0,0 +1,73 @@ +# Id.pm + +############################################## +# # +# Autor: n.d.p. / nd@o3media.de # +# # +# Letze Aenderung: n.d.p. / 2001-01-28 # +# # +# ========================================== # +# # +# Funktion: # +# # +# Bereitsstellen einer einmaligen ID # +# # +############################################## + +use strict; + +package Id; +require 5.000; + +##################### +# Funktionsexport +##################### + +require Exporter; +@Id::ISA = qw(Exporter); +@Id::EXPORT = qw(unique_id); + +use vars qw(@table); + +########################################## +# EXPORT # +# # +# sub &unique_id # +# # +# Funktion: # +# Rueckgabe der ID # +########################################## + +sub unique_id { + my $id; + + my $ip=$ENV{'REMOTE_ADDR'}; + my $time=time(); + my $port=$ENV{'REMOTE_PORT'}; + my $rand=int(rand(time())); + $ip = hex(join ('',map {sprintf ('%02X',$_)} split (/\./,$ip))); + + join '',map {to_base64 ($_)} (substr ($time,-9), $port, $ip, $rand, $$); +} + +sub to_base64 ($) { + my $x = shift; + my $y = $table[$x % 64]; + + while ($x = int ($x/64)) {$y = $table[$x % 64] . $y} + + # Rueckgabe + $y; +} + +BEGIN { + srand(time()^$$); + @table = ('a'..'z','-','0'..'9','A'..'Z','_'); +} + +# making 'require' happy +1; + +##################### +# end of Id +##################### \ No newline at end of file