Home  >  Article  >  php教程  >  用php来获得客户端服务器ip的方法

用php来获得客户端服务器ip的方法

WBOY
WBOYOriginal
2016-06-13 11:32:421544browse

 

echo "当前脚本服务器的主机名:".gethostbyaddr($_SERVER['REMOTE_ADDR'])."<br><hr>";
echo "获得当前运行PHP脚本(页面)所在的服务器的 IP 地址:".$_SERVER['SERVER_ADDR']."<br><hr>";
echo "获得当前运行PHP脚本(页面)所在的服务器的 主机名:".$_SERVER['SERVER_NAME'];
echo '<hr>';

echo '客户端ip'. $_SERVER['REMOTE_ADDR'];
echo '<br>';
echo '客户端ip'.getenv('REMOTE_ADDR');
echo "<br>";
echo '服务器主机ip'.gethostbyname("www.qq.com");

?>

运行出来:
当前脚本服务器的主机名:XYL-PC
获得当前运行PHP脚本(页面)所在的服务器的 IP 地址:127.0.0.1
获得当前运行PHP脚本(页面)所在的服务器的 主机名:localhost
客户端ip127.0.0.1
客户端ip127.0.0.1
服务器主机ip61.135.169.105

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn