How do I get reliable COMPUTERNAME?
am 05.11.2009 17:16:24 von Andrew Ballard
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How do I get reliable COMPUTERNAME?
am 05.11.2009 20:03:39 von List Manager
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
Re: How do I get reliable COMPUTERNAME?
am 05.11.2009 21:11:38 von Andrew Ballard
On Thu, Nov 5, 2009 at 2:03 PM, Jim Lucas wrote:
> 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 look=
ed at the
> data in the output of phpinfo().
>
> The only place that I can find the information that you are looking for i=
s
> available in the "PHP Configuration" section and it is in the System info=
rmation.
>
> So, looking at the phpinfo() page, I noticed the first comment down had a
> method/function for converting the output of phpinfo() into a multidimens=
ional
> 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 =3D phpinfo_array(TRUE);
> list(, $server_name) =3D explode(' ', $data['PHP Configuration']['System'=
]);
> print( $server_name );
>
> This will give you what you are looking for.
>
> Jim
>
Close, but not quite what I need. On the Windows systems, the System
value is "Windows NT [hostname] [build]", so that just returns "NT".
Thanks, though. :-) You never know when something like that might be
useful.
I found php_uname('n') which looks like it will return the information
I'm after without having to dissect strings, and it appears to work
just fine across platforms.
Andrew
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php