<?php
echo '<b>Your ip has now been logged:</b> ';
echo $_SERVER["REMOTE_ADDR"];
$myip = "144.141.53.98"; //so it does not log your IP and spam up the log file
//echo ' Your ip: ';
if ( isset($_SERVER["REMOTE_ADDR"]) ) {
echo '' . $_SERVER["REMOTE_ADDR"] . ' ';
//echo "You are using Localhost";
} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) {
echo '' . $_SERVER["HTTP_X_FORWARDED_FOR"] . ' ';
//echo "Your ip is forwarded";
} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) ) {
echo '' . $_SERVER["HTTP_CLIENT_IP"] . ' ';
//echo "You ip is not forwarded";
}
$file = fopen("ips.txt", "a+");
fwrite($file,$_SERVER["REMOTE_ADDR" ]."\n");
?>
现在好了以下这行代码
$myip = "144.141.53.98"; //so it does not log your IP and spam up the log file
我希望如果一个ip已经记录在日志文件中,那么它将不会再次记录ip
请帮帮忙?
答案 0 :(得分:0)
<?php
echo '<b>Your ip has now been logged:</b> ';
echo $_SERVER["REMOTE_ADDR"];
$myip = "144.141.53.98"; //so it does not log your IP and spam up the log file
//echo ' Your ip: ';
$ip = $_SERVER['REMOTE_ADDR'];
if ( isset($_SERVER["REMOTE_ADDR"]) ) {
echo '' . $_SERVER["REMOTE_ADDR"] . ' ';
//echo "You are using Localhost";
} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) {
echo '' . $_SERVER["HTTP_X_FORWARDED_FOR"] . ' ';
//echo "Your ip is forwarded";
} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) ) {
echo '' . $_SERVER["HTTP_CLIENT_IP"] . ' ';
//echo "You ip is not forwarded";
}
$file = file_get_contents('ips.txt');
// No Duplicate IP Address's
if(strpos($file, $ip) !== false)
{
die("<br><br>Your IP Address: ".$ip." has already been logged.");
}
//Write IP To file
$file = fopen("ips.txt", "a+");`enter code here`
fwrite($file,$_SERVER["REMOTE_ADDR" ]."\n");
fclose($file);
?>