Important alert: (current site time 7/15/2013 11:23:24 AM EDT)
 

VB icon

PhP IP Client Logger

Email
Submitted on: 2/9/2002 8:22:10 PM
By: Kevin Leonardi  
Level: Intermediate
User Rating: By 18 Users
Compatibility: PHP 4.0
Views: 65920
(About the author)
 
     Detect Client IP, save it to file(include first time,last time hit) and count client hit.

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :PhP IP Client Logger
//**************************************
please vote me ! if you like this code.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: PhP IP Client Logger
// Description:Detect Client IP, save it to file(include first time,last time hit) and count client hit.
// By: Kevin Leonardi
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=539&lngWId=8//for details.//**************************************

<!--
/*************************************************************************/
/* Script Name : IP Logger 												 */
/* Description : Detect Client IP, save it to file, and count client hit */
/* Author : Kevin Leonardi */
/* Email: fotx@yahoo.com */
/*										 */
/* Please Vote Me if you like my script! :)								 */
/*************************************************************************/
//-->
<?php
 $found = "false";
 $filename = "count.inc";
 if (file_exists ($filename))
 {$fp = fopen($filename,"r+");}
 else{$fp = fopen($filename,"w");}
 $offset = 0;
 $cnt = 1;
 while ($row = fgets($fp,4096)) {
$cols = explode(";",$row);
if ($cols[0] == $HTTP_SERVER_VARS["REMOTE_ADDR"]){
 $cols[1]++; // increase counter;
 $cnt = $cols[1];
 $cols[3] = date("M/d/Y_H:i:s"); //save hour minute seconds _ month date year
 fseek($fp,$offset);
 fputs($fp,implode(";",$cols));
 $found = "true";
}
$offset = ftell($fp);
 }
 if ($found=="false"){
$cols = array($HTTP_SERVER_VARS["REMOTE_ADDR"],1,date("M/d/Y_H:i:s"),date("M/d/Y_H:i:s"),"\n");
fputs($fp,implode(";",$cols));
 }
 fclose($fp);
?>
<!--
/**************************************************************************/
/*
/* If you'd like this below messages disappear, just remark them with "//"
/* at the every beginning of the line.								 
/*************************************************************************/
//-->
<HTML>
<HEAD><TITLE>IP Logger</TITLE></HEAD>
<BODY BGCOLOR="#000000">
<font face="Courier,Verdana,Arial" size=3 Color="#FFFFFF">
<b>YOUR IP ADDRESS : <font color="red"><?php echo $HTTP_SERVER_VARS["REMOTE_ADDR"]."<br>"; ?></b></font>
You've been hit this site <font color="red"><b><?php echo $cnt;?></b></font> times 
since <font color="cyan"><b><?php echo eregi_replace("_"," at ",$cols[2]);?>.<br></b></font>
Last time I saw you : <font color="Yellow"><b><?php echo eregi_replace("_"," at ",$cols[3]);?></b></font>.
<br><br>
<font color="lime"><b>Vote Me! if you like this code.</b></font>
<font>
</BODY>
</HTML>


Other 3 submission(s) by this author

 


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 Intermediate 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

7/14/2002 6:17:30 AMcharlie

i dont know if it is my setup with ics and apache but i have found some times the script will screw up and will record over and over i let it go for 30 seconds and it made a file 2 megs this could be very dangeruos to a server...

charlie
(If this comment was disrespectful, please report it.)

 
3/29/2003 3:11:35 PM

this source code not logging for next ip address the put is wrong and create a looping storage. Very Bad !!
(If this comment was disrespectful, please report it.)

 
6/21/2003 1:17:19 AM

ghjg
(If this comment was disrespectful, please report it.)

 
2/26/2004 7:32:22 AM

The putting back of a line in the file after being detected, has the flaw that the line that is being written has to be exactly as long as the original one. Else information of the next line either disappears or appears.
(If this comment was disrespectful, please report it.)

 
7/15/2004 8:38:54 AM

its graet
(If this comment was disrespectful, please report it.)

 
12/1/2006 10:09:37 AMQuang Tien

Thanks, it's really an useful code I need ;-)
(If this comment was disrespectful, please report it.)

 
8/1/2007 8:30:52 PMBernadeth Cuadra

Hi thanks but i want to break my other email add which was hack. Thanks
(If this comment was disrespectful, please report it.)

 
8/1/2007 8:42:06 PMBernadeth Cuadra

pls instruct me how to use this program
(If this comment was disrespectful, please report it.)

 
8/7/2007 1:56:40 AMRiecho

Where is the file?
(If this comment was disrespectful, please report it.)

 

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.