VB icon

Logging IP's

Email
Submitted on: 1/1/2015 10:59:00 AM
By: Klaus Andersen (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 1426
 
     This is basically an IP-logger, which keeps a record of if a person with that ip has been there before. This is great for counters which will prevent refresh-increasing the count. Just place the counter-events witin the correct function. The Welcome-part and not the Welcome back.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Logging IP's
// Description:This is basically an IP-logger, which keeps a record of if a person with that ip has been there before.
This is great for counters which will prevent refresh-increasing the count. Just place the counter-events witin the correct function. The Welcome-part and not the Welcome back.
// By: Klaus Andersen (from psc cd)
//
// Returns:The main function returns true and false, depending on if the curren ip of the browser is in the file.
//
// Assumes:Basic php knowledge. But clip and paste will work just as good.
//
// Side Effects:There might be bugs, I havent tested it enough, if there is a flaw please post a reply.
//**************************************

<?php
if (!$filename) { //check if it is in the dir
$filename = "default.txt"; //the default file
if (file_exists("$filename")) {
//echo "The file exists.<br>"; 
//early experiments
}
else {
$fp = fopen($filename,"a+");
fputs($fp,"999.555.444.21\n"); 
//999.555.444.21
//just so that there is something in the file 
//at the beginning
fclose($fp); 
}
}
//the main code
function ticker($filename,$remoted,$mode,$stuff) {
$fp = fopen("checklist.txt","w+");
$filename2 = "checklist.txt"; 
//the checklist 
//is just a base of comparison
// i found that comparing $REMOTE_ADDR and the
// other file had some flaws
// so writing a new one worked best with the 
// same content, it was probably because of the
// linefeed character
fputs($fp,"$remoted\n");
fclose($fp);
$check_var = 0;
$inlines = file($filename2);
$inline = file($filename);
$number_of_lines = count($inline);
for($x = 0; $x <= $number_of_lines ;$x++){
echo "$inlines[0]";
echo "<br>$inline[$x]";
if ($inlines[0] == $inline[$x]) {
$check_var = 1;
}
}
return $check_var;
}
if (!ticker($filename,$REMOTE_ADDR,null,null)) {
$fp = fopen($filename,"a+");
fputs($fp,"$REMOTE_ADDR\n");
fclose($fp);
echo "WELCOME FFS!";
}
else {
echo "WELCOME BACK FFS!";
}
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.