Home  >  Article  >  Backend Development  >  How to use php to get the client server ip_PHP tutorial

How to use php to get the client server ip_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:03858browse

echo "当前脚本服务器的主机名:".gethostbyaddr($_SERVER['REMOTE_ADDR'])."

"; echo "获得当前运行PHP脚本(页面)所在的服务器的 IP 地址:".$_SERVER['SERVER_ADDR']."

"; echo "获得当前运行PHP脚本(页面)所在的服务器的 主机名:".$_SERVER['SERVER_NAME']; echo '
'; echo '客户端ip'. $_SERVER['REMOTE_ADDR']; echo '
'; echo '客户端ip'.getenv('REMOTE_ADDR'); echo "
"; echo '服务器主机ip'.gethostbyname("www.qq.com"); ?>

Run it out:
The host name of the current script server: XYL-PC
Get the IP address of the server where the PHP script (page) is currently running: 127.0.0.1
Get the host name of the server where the PHP script (page) is currently running: localhost
Client ip127.0.0.1
Client ip127.0.0.1
Server host ip61.135.169.105

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/372090.htmlTechArticle?php echo The host name of the current script server: .gethostbyaddr($_SERVER['REMOTE_ADDR']).br / hr /;echo Get the IP address of the server where the PHP script (page) is currently running: .$_SERVER...
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