tags:

views:

878

answers:

2

I have a php application that is installed on several servers and all of our developers laptops. I need a fast and reliable way to get the server's hostname or some other unique and reliable system identifier. Here's what we have thought of so far:

<? $hostname = (!empty($_ENV["HOSTNAME"])) ? $_ENV["HOSTNAME"] : env('HOSTNAME'); ?>

<? $hostname = gethostbyaddr($_SERVER['SERVER_ADDR']); ?>

<? $hostname = exec('hostname'); ?>

What do you think?

+1  A: 

What about gethostname()?

Edit: This might not be an option I suppose, depending on your environment. It's new in PHP 5.3. php_uname('n') might work as an alternative.

zombat
A: 

php_uname but I am not sure what hostname you want the hostname of the client or server.

plus you should use cookie based approach

RageZ
need to hostname of the server, not the client.
mattweg
php_uname should make it, are you sure those hostname won't have any duplicate ?
RageZ