Click to See Complete Forum and Search --> : Ip Logger?
Baby Jai
08-20-2003, 06:52 PM
Ok I have this script and its writing to the file ip.txt, but i dont know how to configure
<?
/* SIMPLE 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("$ip.txt", "a");
fputs($fp, "$iprn");
flock($fp, 3);
fclose($fp);
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);
fclose($fp);
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.
*/
?>
ive just tested the scrip and all seems to be fine have you chmod to 777 on your ip.txt file?
you can strip away the txt in the script looks like this
<?php
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
fputs($fp, "$iprn");
flock($fp, 3);
fclose($fp);
PRINT("Your Ip was logged.....$ip");
?>
oh you are on a unix server aint ya?
see your PM for a working link
Baby Jai
08-20-2003, 07:12 PM
im on Apache server
Baby Jai
08-20-2003, 07:15 PM
ok im putting this in a index.html file. Is that possible becuase its not working on my home page
ok the simple way too test things is this
<?PHP
$ip = $_SERVER['REMOTE_ADDR'];
echo "Your IP address is: $ip";
?>
copy paste that into notepad >>save as whatever.php then upload to your dir and test in your browser let me know the results...
ahh yes it should be saved as index.php
or whatever.php
:D
Baby Jai
08-20-2003, 07:22 PM
is there not a way to embedd this PHP into a index.thml?
ahh now I know what you wana doo just put this line in the body of your index.html and save it as index.shtml and you will get what you want
<!--#echo var="REMOTE_ADDR"-->
if you fo to the root of the I sent you you will see an example.
Baby Jai
08-20-2003, 07:33 PM
Ok check it, I have to keep it as index.html being that so many sites have this link. Is there no other way?
yes php can be embedded into html but as far as I know the variables cannot be passed back into sinple html but we are streching my knowledge of php here time for someone else to take over here PYRO where are you? :D
Baby Jai
08-20-2003, 07:48 PM
yeah where is he?
Just got back... ;)
By default, PHP is only parsed on pages with a .php extention. This saves the server from having to run every page through the PHP parser. If you want .htm and .html pages to be run through the PHP parser, you'll have to add a .htaccess file that looks something like this:
AddType application/x-httpd-php .php .htm .html
That will tell the server to parse .htm and .html files as PHP files...
Baby Jai
08-20-2003, 09:38 PM
man, thats to difficult, there is no way to run an ip logger via html then?
Not unless you decide to use an iframe, and run the a PHP page in that...
Originally posted by pyro
[B]
AddType application/x-httpd-php .php .htm .html
B]
thats a usefull snippet thanks pyro
Baby Jai
08-24-2003, 12:35 AM
Ok here Is a couple of problem, one my ip.txt is not getting the ip written to it and its CHMOD to 777, I put it in the main directory and in the directory of the htaccess file. Also this is another error im getting
Warning: fopen(ip.txt): failed to open stream: Permission denied in /home/babyjai/www.babyjai.com/docs/401.php on line 24
Warning: fputs(): supplied argument is not a valid stream resource in /home/babyjai/www.babyjai.com/docs/401.php on line 25
Warning: flock(): supplied argument is not a valid stream resource in /home/babyjai/www.babyjai.com/docs/401.php on line 26
Warning: fclose(): supplied argument is not a valid stream resource in /home/babyjai/www.babyjai.com/docs/401.php on line 27
Baby Jai
08-24-2003, 12:37 AM
Ok i fixed that problem, it was a problem with tip.txt file, now how come the ips arent getting written to it?
Da Warriah
08-24-2003, 02:41 PM
looks like this line:
fputs($fp, "$iprn");
you shouldnt need the quotes around $iprn...
diamonds
08-24-2003, 04:39 PM
It would not matter if it was enclosed id double-quotes or not. PHP would sub-in the variable.
<?php
$var1 = 'var1';
$var2 = 'var2';
$var3 = "$var1 and $var2";//note the d-quotes
echo "$var1$var2".$var3//would echo :
/* "var1var2var1 and var2" */
//Now single quotes:
echo '$var1$var2'.$var3//would echo :
/* "$var1$var2var1 and var2" */
?>
See?
Baby Jai
08-24-2003, 04:58 PM
ok so whats the result on why its not logginh
Da Warriah
08-24-2003, 05:43 PM
i knew that, but i just couldnt see any other problem with the code:o
Baby Jai
08-24-2003, 05:52 PM
So what could i do to resolve this issue then?
Are you one a *nix or Windows server? If it is Windows, you can't lock the files. Also, you aren't really locking the file, only releasing it (??)
If you are on a *nix server, try:
<?php
$log_file = "ip.txt"; // CHMOD to 666
$ip = $_SERVER['REMOTE_ADDR'];
$fp = fopen("$log_file", "a");
flock ($fp, 2); #lock the file
fwrite($fp, "$ip");
flock($fp, 3); #release the file
fclose($fp);
echo "Your Ip was logged.....$ip";
?>Anyway, I'd be willing to bet once you fix your variable in the fputs, it will probably work fine.
You currently have :
fputs($fp, "$iprn"); #there is no variable $iprn
but you must have meant:
fputs($fp, "$ip");
Baby Jai
08-25-2003, 02:01 PM
<?php
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
fputs($fp, "$iprn");
flock($fp, 3);
fclose($fp);
PRINT("Your Ip was logged.....$ip");
?>
Im on a apache server, tell me whats wrong with this script and why its not logging. I will fix the iprn and see if it changed
I did so in the above post...
Originally posted by pyro
You currently have :
fputs($fp, "$iprn"); #there is no variable $iprn
but you must have meant:
fputs($fp, "$ip");I also recommended a better way of writing the script.
And lastly, Apache can run on either Window or *nix boxes...
Baby Jai
08-25-2003, 02:05 PM
Ok great it worked, but one problem when it does the ips it looks like this, how could i do it so its enetered like one a line
68.37.151.14368.37.151.14368.37.151.143
Using mine:
fwrite($fp, "$ip\n");Using yours:fputs($fp, "$ip\n");
Baby Jai
08-26-2003, 03:28 PM
How do i add a time and date next to the IP hackers???
Before the fwrite line, add this:
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$ip .= " $date at $time";You get a different format for the date and time, if you'd like. Just see http://www.php.net/date...
Baby Jai
08-26-2003, 03:58 PM
yup looks great, 2 problems
1) The time is 3 hours behind on the page.
2) It doesnt log the time and date in the ip.txt
Almot there good buddy. How is that image your doing for me coming along? ;)
#1, it displays the server time, not your local time
#2, let me see your full script, again...
#3, I'll email you about it.
Baby Jai
08-26-2003, 04:11 PM
1) The time is 3 hours behind on the page.
2) It doesnt log the time and date in the ip.txt
1) Anyway to change that at least for the code and put EST behind it?
2) is it possible to do that?
here is the code
<?php
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$ip .= " $date at $time";
fputs($fp, "$ip\n");
flock($fp, 3);
fclose($fp);
PRINT("Your Ip was logged .....$ip");
?>
Just ran this through my server and it worked a charm...
<?php
$log_file = "ip.txt"; // CHMOD to 666
$ip = $_SERVER['REMOTE_ADDR'];
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$ip .= " $date at $time";
$fp = fopen("$log_file", "a");
flock ($fp, 2); #lock the file
fwrite($fp, "$ip");
flock($fp, 3); #release the file
fclose($fp);
echo "Your Ip was logged.....$ip";
?>
Oh, also take a look at http://forums.webdeveloper.com/showthread.php?s=&threadid=14498#post77221
Baby Jai
08-26-2003, 05:09 PM
works great! Thanks and I took a look at that, although this isnt something I need but its cool. I see where you were going with it! ;)
Great! Glad it helped out... :)