Monday, May 28, 2007

PHP-IP Logger


ok. First off,start off by creating a text file named ip.txt.
Upload that to your server,and CHMOD it to 777.

We did that because that is where the IPS are going to be logged.
We CHMODED it to 777 because thats read,write,and executr persmissions. So that the file is ab;le to write to it.
Now, the actuall PHP script. Make a new document
In it,type this:

$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
fputs($fp, "$iprn");
flock($fp, 3);
PRINT("Your Ip was logged.....$ip");

Now lets review some of this.
The $logfile is just what is sounds like.
The log file that the IPS will be logged to.
The $ip variable is confusing in this.
It should go like something like $ip = $REMOTE-ADDV.
But in this case it goes like $ip = getenv('REMOTE_ADDR');
Same thing. They both get the USERS IP.

$fp = fopen("$log_file", "a");
fputs($fp, "$iprn");
flock($fp, 3);

What that does is write to the script.
$fp= fopen then the log filevariable is to tell the script what it is writing to.

Then ya got PRINT("YOUR IP WAS LOGGED...$IP");
That tells the user there IP was logged,and shows it to them.
Well,there ya have it. A very simple IP logging script.

Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script.

No comments: