来看看代码:
复制代码 代码如下:
echo "(1)浏览当前页面的用户的 IP 地址为:";
echo $_SERVER['REMOTE_ADDR'];
echo "
";
echo "(2)浏览当前页面的用户的 IP 地址为:";
echo getenv('REMOTE_ADDR');
echo "
";
echo "主机 www.baidu.com 的 IP 地址为:";
echo gethostbyname(www.baidu.com);
它的输出结果为:
(1)浏览当前页面的用户的 IP 地址为:127.0.0.1
(2)浏览当前页面的用户的 IP 地址为:127.0.0.1
主机 www.baidu.com 的 IP 地址为:61.135.169.105
关于获取客户端的 IP 地址,有俩方法:
第一个是使用:
?$_SERVER['REMOTE_ADDR']
它正在浏览当前页面用户的 IP 地址,这里的输出结果为 127.0.0.1,因为这是在本地测试,输出的是我本地的环路地址。
第俩个是使用:
?getenv('REMOTE_ADDR')
这里使用了函数 getenv : Gets the value of an environment variable(得到各种环境变量的值),返回值:Returns the value of the environment variable varname, or FALSE on an error(失败的话返回 FALSE).
关于获取服务器端的 IP 地址:
?gethostbyname(www.baidu.com)
这里使用了函数 gethostbyname : Get the IP address corresponding to a given Internet host name(通过给定的一个主机名字而得到它的 IP 地址),返回值:Returns the IP address of the Internet host specified by hostname or a string containing the unmodified hostname on failure(失败的话返回原样的输入字符主机名).
注意这里的最后一句,也就是说,如果失败的话,它会将原样输出,例如:
?echo "无效主机 iwilldown 的 IP 地址为:";
echo gethostbyname("iwilldown");
输出:
?无效主机 iwilldown 的 IP 地址为:iwilldown
当然,这个可不是 IP 地址….

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),