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

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

Jun 13, 2016 am 11:32 AM
echophphostclientmethodserveruseofScriptget

 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools