Brad_Armitage
05-26-2004, 06:11 PM
Here I have a PHP session counter that also records the IP of a person visiting the site in a text file:
<?php
session_start();
session_register('counter');
$CountFile = "folder_name/counter.txt";
$Count = file($CountFile);
$Count = implode("", $Count);
if(!$_SESSION['counter']){
$counter = true;
$OpenFile = fopen($CountFile, "r+");
$Count++;
$user_ip = GetHostByName($_SERVER['REMOTE_ADDR']);
$banned = array('142.67.105.80', '142.67.105.81');
if (!in_array($user_ip, $banned)) {
if($OpenFile){
fwrite($OpenFile, $Count);
fclose($OpenFile);
}
}
// loads the ip file into an array
$file = file("folder_name/ipaddress.txt");
// checks to see if the users ip is already in the text file
if (!in_array($user_ip, $file) {
$ip_file = "folder_name/ipaddress.txt";
$ip = fopen($ip_file, "a+");
fwrite($ip, "$user_ipn");
fclose($ip);
}
}
?>
What I want it to do is check to see if the IP address from the current session is already recorded in the text file, and if it is, don't record it again, if not record it once then start on a new line. It works well except it still records the IP address from a session more then once. HELP would be great!! :D
<?php
session_start();
session_register('counter');
$CountFile = "folder_name/counter.txt";
$Count = file($CountFile);
$Count = implode("", $Count);
if(!$_SESSION['counter']){
$counter = true;
$OpenFile = fopen($CountFile, "r+");
$Count++;
$user_ip = GetHostByName($_SERVER['REMOTE_ADDR']);
$banned = array('142.67.105.80', '142.67.105.81');
if (!in_array($user_ip, $banned)) {
if($OpenFile){
fwrite($OpenFile, $Count);
fclose($OpenFile);
}
}
// loads the ip file into an array
$file = file("folder_name/ipaddress.txt");
// checks to see if the users ip is already in the text file
if (!in_array($user_ip, $file) {
$ip_file = "folder_name/ipaddress.txt";
$ip = fopen($ip_file, "a+");
fwrite($ip, "$user_ipn");
fclose($ip);
}
}
?>
What I want it to do is check to see if the IP address from the current session is already recorded in the text file, and if it is, don't record it again, if not record it once then start on a new line. It works well except it still records the IP address from a session more then once. HELP would be great!! :D