Re: How do I get reliable COMPUTERNAME?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrew Ballard wrote:
> I want to store the name of the computer that is executing a script in
> some log tables. (Our servers are load balanced, and I'd like to be
> able to determine which physical machine is serving each request.)
> 
> On my development machine (Windows PC running the debugger in Zend
> Studio), I can find the name in three places:
> 
> getenv('COMPUTERNAME')
> $_ENV['COMPUTERNAME']
> $_SERVER['COMPUTERNAME']
> 
> On the development server, only the first works; $_ENV and $_SERVER
> both return NULL and throw an undefined index notice.
> 
> I'm concerned about the reliability of all of these methods, since it
> seems that they are not always available and all three can be easily
> overridden inside a script. However, I notice that the header
> generated by phpinfo() remains correct even when I manually spoofed
> all three values on my development machine. Is there a reliable way to
> find this value?
> 
> Andrew
> 

Well, I looked at all the variables that are available.  Then I looked at the
data in the output of phpinfo().

The only place that I can find the information that you are looking for is
available in the "PHP Configuration" section and it is in the System information.

So, looking at the phpinfo() page, I noticed the first comment down had a
method/function for converting the output of phpinfo() into a multidimensional
array.  Taking the output of that users function, you can access the data the
data you are looking for.

So, here is a link to the phpinfo() page.

http://php.net/phpinfo

>From there, get the function called phpinfo_array()

take the output of that and run it through the following set of commands.

$data = phpinfo_array(TRUE);
list(, $server_name) = explode(' ', $data['PHP Configuration']['System']);
print( $server_name );

This will give you what you are looking for.

Jim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux