php 获取客户端的计算机名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3003385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the client's computer name
提问by Anup Prakash
I am getting the client's (website user's) IP address. Now I'd like to go one step further by knowing the user's computer name. So far, my research has not turned up anything to aid me in retrieving this information.
我正在获取客户端(网站用户)的 IP 地址。现在我想更进一步,了解用户的计算机名称。到目前为止,我的研究还没有发现任何可以帮助我检索这些信息的信息。
Is it possible to use the user's IP address, or some other means, to get my visitor's computer name using PHP?
是否可以使用用户的 IP 地址或其他方式通过 PHP 获取访问者的计算机名称?
回答by moeiscool
PHP 5.4+
PHP 5.4+
gethostbyaddr($_SERVER['REMOTE_ADDR'])
回答by Quentin
You can perform a reverse DNS lookup using gethostbyaddr().
您可以使用gethostbyaddr().
Note that this will give you the name of the host the request came from according to reverse DNS.
请注意,这将根据反向 DNS 为您提供请求来自的主机的名称。
- It will not give you a result if reverse DNS isn't set up
- It will not give you the Windows name of the computer
- It will give you the name of the router if NAT is involved or proxy if a proxy is involved.
- 如果没有设置反向 DNS,它不会给你结果
- 它不会为您提供计算机的 Windows 名称
- 如果涉及 NAT,它将为您提供路由器的名称,如果涉及代理,它将为您提供代理的名称。
回答by cherouvim
Not possible with plain php running on the server. It'd be a security/privacy issue to know details of the client such as computer name, mac address, contents of his drive.
在服务器上运行纯 php 是不可能的。了解客户端的详细信息(例如计算机名称、mac 地址、驱动器内容)将是一个安全/隐私问题。
You need some sort of application running on the client's machine in order to get this.
您需要在客户端机器上运行某种应用程序才能获得它。
回答by aioobe
If you're referring to the hostname (displayed for instance by the hostnamecommand on linux) of the computer doing the request:
如果您指hostname的是执行请求的计算机的主机名(例如由linux 上的命令显示):
That information is not included in an HTTP request. (That is, it's impossible for PHP to figure out.)
该信息不包含在 HTTP 请求中。(也就是说,PHP 不可能弄清楚。)
You could do a reverse DNS lookup, but that's probably not what you want anyway.
您可以进行反向 DNS 查找,但这可能不是您想要的。
回答by Aditya Gupta
This is all that you could get using just PHP (you may try these butIi dont think this is what you actually needed):
这就是您可以仅使用 PHP 获得的全部内容(您可以尝试这些,但我认为这不是您真正需要的):
gethostname()
gethostbyname(gethostname())
$_SERVER['HTTP_HOST']
$_SERVER['SERVER_SIGNATURE']
$_SERVER['SERVER_NAME']
$_SERVER['SERVER_ADDR']
$_SERVER['SERVER_PORT']
$_SERVER['REMOTE_ADDR']
gethostbyaddr($_SERVER['REMOTE_ADDR'])
php_uname()
回答by Eric Mickelsen
The only thing you could do is try to get a DNS name for the client. "Computer Name" is a Windows made-up thing. Just call the built-in function gethostbyaddr()with the client's IP address. However, it won't always (hardly ever) work.
您唯一能做的就是尝试获取客户端的 DNS 名称。“计算机名称”是 Windows 编造的东西。只需gethostbyaddr()使用客户端的 IP 地址调用内置函数即可。但是,它不会总是(几乎永远不会)起作用。
回答by indianwebdevil
You can do this by
你可以这样做
$_SERVER['REMOTE_HOST']
$_SERVER['REMOTE_HOST']
'REMOTE_HOST' - The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user.
'REMOTE_HOST' - 用户查看当前页面的主机名。反向 dns 查找基于用户的 REMOTE_ADDR。
Note:Your web server must be configured to create this variable. For example in Apache you'll need HostnameLookups On inside httpd.conf for it to exist. As David mentioned you can also use . gethostbyaddr()
注意:您的 Web 服务器必须配置为创建此变量。例如,在 Apache 中,您需要在 httpd.conf 中使用 HostnameLookups On 才能使其存在。正如大卫提到的,你也可以使用 . gethostbyaddr()
Pls go thru all the comments in the url before actually using the function.
在实际使用该功能之前,请仔细阅读 url 中的所有评论。
回答by Hamid
Do something lik this:
做这样的事情:
<?php
//get host by name
echo gethostname();
echo "<br>";
//get OS
echo php_uname();
?>

