Page 1 of 1

IP Logger

Posted: Wed Nov 05, 2003 3:18 am
by Dale
I've made an IP Logger:

Heres the page that logs it:
http://dframe.t35.com/iplogger/test.php

Then click the ADMIN SECTION link, then click VIEW IPS in the menu. IT will display them with the date aswell. Now what i wanna know is how would i get it to display the numbers to the left of it?

[EXAMPLE]

1 November 2nd 2003 123.456.7.8
2 November 2nd 2003 123.456.7.8
3 November 2nd 2003 123.456.7.8
4 November 3rd 2003 123.456.7.8
5 November 3rd 2003 123.456.7.8
6 November 3rd 2003 123.456.7.8
7 November 4th 2003 123.456.7.8

[/EXAMPLE]

Posted: Wed Nov 05, 2003 3:55 am
by twigletmac
The code you're using for display is...?

Mac

Posted: Wed Nov 05, 2003 3:57 am
by Dale
Woops forgot, sorry :)

Code thats loggin and sending to logs.txt

Code: Select all

<? 

$iplog="ips.txt";
$TestLog=fopen($iplog,"r");
fclose($TestLog);
$Date=date("F j, Y");
$IP=$HTTP_SERVER_VARS["REMOTE_ADDR"];
$Logging="<tr valign="top">
<td width="50%"><font face="Verdana" size="1">$Date</font></td>
<td width="50%"><font face="Verdana" size="1">$IP</font></td>
</tr>";
$Post = fopen("$iplog","a");
        fputs($Post,$Logging);
        fclose($Post);
?>

Posted: Wed Nov 05, 2003 6:22 pm
by scorphus
Give it a try:

Code: Select all

<?php
$iplog="ips.txt";
$TestLog=fopen($iplog,"r");
fclose($TestLog);
$nextLine = count(file($iplog)) + 1;
$Date=date("F j, Y");
$IP=$HTTP_SERVER_VARS["REMOTE_ADDR"];
$Logging="<tr valign="top"><td width="10%"><font face="Verdana" size="1">$nextLine</font></td><td width="40%"><font face="Verdana" size="1">$Date</font></td><td width="50%"><font face="Verdana" size="1">$IP</font></td></tr>\n";
$Post = fopen("$iplog","a");
fputs($Post,$Logging);
fclose($Post);
?>
See more info on [php_man]file[/php_man] and count

Tis may cause your server to speed dow due to the possibility of the ips.txt file becomes very very large. So keep cleaning it from time to time... Or implement a counter in a separate file to keep track of the access number.

Hope that helps. Tchau,
Scorphus.

Posted: Thu Nov 06, 2003 3:10 am
by Dale
I'll also probably add a delete button which deletes all the content in the txt file.

(How would i do that?)

Posted: Thu Nov 06, 2003 6:09 am
by scorphus
You could write a dellogs.php:

Code: Select all

<?php
/* This script creates a backup copy of ips.txt and creates a new empty ips.txt
 * It deletes a backup file ips.txt.bak if it exists
 * It copy the current ips.txt to a new ips.txt.bak
 * And then creates a new ips.txt
 */

$iplog="ips.txt";

// Checks if ips.txt.bak exists and attempts to delete it

if (file_exists($iplog.'.bak') && !unlink($iplog.'.bak')) {
	print ("failed to delete $iplog.bak...<br>\n");
}

// Attempts to copy ips.txt to ips.txt.bak
if (!copy($iplog, $iplog.'.bak')) {
	print ("failed to copy $iplog to $iplog.bak...<br>\n");
}

// Attempts to create a new ips.txt
$TestLog = @fopen($iplog, "w");
if (!$TestLog) {
	print ("failed to create new $iplog...<br>\n");
}
fclose($TestLog);
?>
and make your delete button (<a href="dellogs.php"><img src="button.jpg"></a>) to do the job.

Hope that helps your understanding!

Cheers,
Scorphus.