如何使用PHP查找服务器的请求IP

问题描述 投票:0回答:1

我正在试图查看我的服务器请求IP是什么。例如。

<?php
$contents = file_get_contents("https://example.com");
?>

我想知道我的服务器使用什么IP连接到example.com。我不能使用像IPLookUp这样的工具,因为它只获取响应的IP,如果我的域名中有cloudflare,那么它将继续显示cloudflares代理IP。


如果我使用$_SERVER['SERVER_ADDR']它只是告诉我当地的IP 127.0.0.7

php ip file-get-contents
1个回答
0
投票

使用gethostbyname

gethostbyname ( string $hostname )

© www.soinside.com 2019 - 2024. All rights reserved.