I have a script of someone and i want to alter it a bit, but i don't know how to.
What i want:
-I want a count and ip count on my home page.
-I want to show the count on another (certified) page.
-On that page there also must be a list of IP numbers that had been stored.
The script:
<?
//Set Variables
$IPfilePath = "ip_data.dat"; // Path to IP number file
$countFilePath ="count.dat"; //Path to Count file
$overRide = 0;//Toggles IP logging: 0=On 1 =Off
$readErr = "Read error, contact [email]info@mustalweb.co.uk[/email] for help";
$writeErr = "Write error, contact [email]info@mustalweb.co.uk[/email] for help";
$hitMessage1 ="Simple hit counter ";//Text before...
$hitMessage2 =" override = ";// and after counter.
//================= No need to change anything after here ========================
$IPnum = "0.0.0.0"; //Set as a String
$userStatus = 0;
// Get the current IP number ------------------------------
$IPnum = getenv("REMOTE_ADDR");
//Get stored IP's from a file --------------------------------
$IPlist = @fopen($IPfilePath, "r")or die($readErr);
$IPdata = fread($IPlist,filesize($IPfilePath));
fclose($IPlist);
//Compare it to the ones stored in ip_data.dat ---
$IParray = explode(" ",$IPdata); //Make array of IPs
// Start comparing IPs
for($ipCount=0;$ipCount<count($IParray);$ipCount++){
if($IPnum != $IParray[$ipCount]){$userStatus = 0;} //New visit by IPnum
elseif($IPnum == $IParray[$ipCount]){$userStatus = 1;}//Been before
}// End for loop
if($overRide == 1){$userStatus = 2;}
// OK it's a new visitor
// Store the IP number in case they ever come back.
// The counter, give it one.
if($userStatus == 0){
$IPfile = @fopen($IPfilePath, "a") or die ($writeErr); // Write the new IP to ip_data.dat
@fwrite($IPfile, " $IPnum") or die($writeErr);
fclose($IPfile);
$incCount = @fopen($countFilePath, "r") or die ($readErr);
$theCount = fread($incCount, filesize($countFilePath));
$theCount++;
fclose($incCount);
$incCount = @fopen($countFilePath, "w") or die ($readErr);
@fwrite($incCount, $theCount) or die ($writeErr);
fclose($incCount);
}
//This ones been before leave the counter alone
elseif($userStatus == 1){
$incCount = @fopen($countFilePath, "r") or die ($readErr);
$theCount = fread($incCount, filesize($countFilePath));
fclose($incCount);
}
//Test mode
elseif($userStatus == 2){
$incCount = @fopen($countFilePath, "r") or die ($readErr);
$theCount = fread($incCount, filesize($countFilePath));
$theCount++;
fclose($incCount);
$incCount = @fopen($countFilePath, "w") or die ($readErr);
@fwrite($incCount, $theCount) or die ($writeErr);
fclose($incCount);
}
echo "$hitMessage1 $theCount $hitMessage2";
?>