Loading... <p>本文介绍如何使用PHP获取用户的真实ip,并且写入到txt文档<br>首先创建一个php文件,将下面代码放到PHP文件中</p><pre><code><?php function getIp() { if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP"); else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR"); else if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR']; else $ip = "unknown"; return ($ip); } //输出ip $myfile = fopen("ip.txt", "a+") or die("Unable to open file!"); $txt = "ip:"; fwrite($myfile, $txt); $txt = getIp(); fwrite($myfile, $txt); $txt = "时间:"; fwrite($myfile, $txt); $txt = date('Y-m-d h:i:s', time()); fwrite($myfile, $txt); $txt = "\n"; fwrite($myfile, $txt); fclose($myfile); ?> </code></pre><p>然后在<head></head>连接起来就可以了<br>本文作者:小小孩子们,转载请注明<br>本文链接<a href="https://www.xxhzm.cn/index.php/archives/14/"><a href="https://www.xxhzm.cn/index.php/archives/14/">https://www.xxhzm.cn/index.php/archives/14/</a></a><br>转载请注明原文地址</p> 猜你想看 cdn.xxhzm.cn免费的静态文件加速服务 每日一学:PHP 中的array_replace函数详解 react学习-JSX(二) cdn.xxhzm.cn 免费的静态资源加速 求助帖!关于axios跨域的问题 - 已解决 nuxt3中文官网nuxt3是一个基于Vue.js的静态站点生成器和应用程序框架 tcping不是windows默认命令, tcping怎么安装? 不限新老9元无限购买dnspod专业版+top域名 H5+CSS3+PHP一款好看的登陆代码 每日一学:PHP 中的array_intersect_uassoc函数详解 最后修改:2022 年 06 月 05 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏