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

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

WBOY
Release: 2016-06-13 11:32:42
Original
1577 people have browsed it

 

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");

?>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template