[Gllug] Unique id fields

Paul Cupis paul at cupis.co.uk
Sat Oct 11 17:42:24 UTC 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 11 October 2003 18:05, will <will at hellacool.co.uk> wrote:
> Hello,
>
> What do people prefer to use when they need to get a unique ID in CGI
> applications?  I am currently generating my own, but have been
> looking at mod_unique_id:
>
> http://httpd.apache.org/docs/mod/mod_unique_id.html
>
> I guess using this means that you have the overhead of generating a
> unique ID for every single request, but is this significant?  What
> methods would people use if not this?

Something like the routine below will(?) generate a unique ID for each 
visitor to the site. It uses MOD_UNIQUE_ID if the Apache server has it 
loaded (recommended) else creates a practically unique ID based on 
other information about the connection. You'll have to pass the hold 
onto the ID once you have generated it, if you want to track the ID 
across requests.

I'm sure it could be improved upon. I have not noticed any significant 
overhead with enabling the module.

sub unique_id {

  # use mod_unique?
  return $ENV{UNIQUE_ID} if exists $ENV{UNIQUE_ID};

  require Digest::MD5;

  my $md5         = new Digest::MD5;
  my $remote_addr = $ENV{REMOTE_ADDR} || 1234;
  my $remote_port = $ENV{REMOTE_PORT} || 9876;
  my $remote      = $remote_addr . $remote_port;

  my $id = $md5->md5_base64( time, $$, $remote );
  $id =~ tr|+/=|-_.|;    # make URI friendly
  return $id;
}


Regards,

Paul Cupis
- -- 
paul at cupis.co.uk
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iEYEARECAAYFAj+IQRcACgkQIzuKV+SHX/kmGQCdH9KqvjlyqYCuHyJI7QOYDvTx
7W0AniVgTZCxNE7ibkmtdFgHCPps9dQ0
=1Nx/
-----END PGP SIGNATURE-----

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list