实际上,我遇到的问题是$_SERVER['REMOTE_ADDR']
按预期返回服务器的公共IP而不是客户端公共IP。我没有使用任何代理,所以肯定不是这样。
<?php
$_SERVER['REMOTE_ADDR'];
?>
以下是$ _SERVER的输出:
[SERVER_NAME] => server public ip
[SERVER_ADDR] => server local ip
[SERVER_PORT] => 80
[REMOTE_ADDR] => server public ip
[DOCUMENT_ROOT] => root dir
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => root dir
[SERVER_ADMIN] => postmaster@localhost
[SCRIPT_FILENAME] => root dir/file.php