php 使用哪个:REMOTE_ADDR 或 SERVER_ADDR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3394367/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:35:10  来源:igfitidea点击:

Which to use: REMOTE_ADDR or SERVER_ADDR

php

提问by syhuro

Any real difference between

之间的任何真正区别

$_SERVER['REMOTE_ADDR']
$_SERVER['SERVER_ADDR']

I'm tracking visitors to a page, and I've always used REMOTE_ADDR, but recently I saw a script that collected both information. Is this a better practice or not needed?

我正在跟踪页面的访问者,我一直使用REMOTE_ADDR,但最近我看到了一个收集这两种信息的脚本。这是更好的做法还是不需要?

回答by Sarfraz

The $_SERVER['REMOTE_ADDR']returns the IP address from which the user is viewing the current page. And $_SERVER['SERVER_ADDR']returns the IP address of the server under which the current script is executing.

$_SERVER['REMOTE_ADDR']返回的IP地址从用户正在浏览当前页面。并$_SERVER['SERVER_ADDR']返回当前脚本在其下执行服务器的 IP 地址。

So what should you use:

那么你应该使用什么:

You should use $_SERVER['REMOTE_ADDR'].

你应该使用$_SERVER['REMOTE_ADDR'].

More Info:

更多信息:

回答by jmz

SERVER_ADDRis the address of the server PHP code is run on. You don't need to collect it. REMOTE_ADDRis the one you want.

SERVER_ADDR是运行 PHP 代码的服务器的地址。你不需要收集它。REMOTE_ADDR是你想要的。