gpt4 book ai didi

php - 如何修改此代码以将 ip 地址记录到另一个文件

转载 作者:可可西里 更新时间:2023-11-01 02:47:50 26 4
gpt4 key购买 nike

请看下面简单的php网页代码

如何修改我的代码以便在我的服务器上创建一个日志文件来记录每个访问者的 ip 以及它是否已成功重定向到正确的页面。类似的东西。

   <?php

$a = $_SERVER['REMOTE_ADDR'];
if ( $a == "117.96.112.122" )
{
header("Location: ad_sams_mobile.html");
return true;
}
else
{
header("Location: ad_other_mobile.html");
return true;
}

?>

最佳答案

查看 PHP 函数 file_put_contents .您需要使用附加标志:

file_put_contents("log.txt", "IP: ". $a .", Location: ad_other_mobile.html", FILE_APPEND);

关于php - 如何修改此代码以将 ip 地址记录到另一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1606739/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com