1 Star 0 Fork 50

NianGui/LikeGirl5.0.0

forked from Ki/LikeGirl5.0.0 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ip.php 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
Ki 提交于 2022-12-22 20:30 . Like_Girl V5.0.0
<?php
function get_ip_city($ip)
{
$ch = curl_init();
$url = 'https://whois.pconline.com.cn/ipJson.jsp?ip=' . $ip;
//用curl发送接收数据
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//请求为https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$location = curl_exec($ch);
curl_close($ch);
//转码
$location = mb_convert_encoding($location, 'utf-8', 'GB2312');
//var_dump($location);
//截取{}中的字符串
$location = substr($location, strlen('({') + strpos($location, '({'), (strlen($location) - strpos($location, '})')) * (-1));
//将截取的字符串$location中的‘,’替换成‘&’ 将字符串中的‘:‘替换成‘=’
$location = str_replace('"', "", str_replace(":", "=", str_replace(",", "&", $location)));
//php内置函数,将处理成类似于url参数的格式的字符串 转换成数组
parse_str($location, $ip_location);
return $ip_location['pro'];
}
$ip = $_SERVER['REMOTE_ADDR'];
$time = gmdate("Y-m-d/H:i:s", time() + 8 * 3600);
$gsd = get_ip_city($ip);
$file = "ip.txt";
$fp = fopen("ip.txt", "a");
$txt = "\n" . "$ip" . "\n" . "$gsd" . "----" . "$time" . "\n";
fputs($fp, $txt);
?>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/NianGui/like-girl5.0.0.git
git@gitee.com:NianGui/like-girl5.0.0.git
NianGui
like-girl5.0.0
LikeGirl5.0.0
master

搜索帮助