<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 8 年前。
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 8 年前。
我尝试使用“gethostbyaddr”将 IP 地址转换为主机名,但没有成功。我使用作为日志文件的 file.text 来分析用户使用了很多或更少的页面。所以我试着删掉使用数组的句子。这是我的代码。
$file=fopen("log.txt","r");
while (!feof($file)) {
$buffer = fgets($file, 4096);
$text= explode(" ",$buffer,10);
$text_2=@$text[1];
$ip=substr($text_2,1,11);
$ip2=gethostbyaddr($ip);
echo"INSERT INTO `log` VALUES ('$ip2');"."<br>"; //Show results
//echo"<br>"; //New line
}
fclose($file);
谢谢
最佳答案
这意味着 gethostbyaddr 失败。
不是因为你的输入,在php文档中找到解释
http://php.net/manual/en/function.gethostbyaddr.php
“成功时返回主机名,失败时返回未修改的 ip_address,或错误输入时返回 FALSE。”
关于php - 为什么使用 "gethostbyaddr"将 IP 地址转换为主机名却不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25358160/