...

View Full Version : Record IP script??



sethberno
11-16-2008, 02:45 AM
Hello all,

I was wondering if anyone could hekp me with a little code that would record the ip of someone that visited a certain page within a forum.

It is only going to be used for security purposes.

thank you for any help!

rangana
11-16-2008, 03:48 AM
You can use a database to record all the IP that have visited on your page and if that IP already exists, don't add.

However, you can also use a simple .txt to append the IP on the list:


$found=false; // Initialize found to false
$ip=$_SERVER['REMOTE_ADDR']; // Get visitor's IP address
$fp=fopen('ip.txt','r'); // @param1 - Open a file with name ip.txt. @param2- argument. Read documentation
$count=0; // Initialize count var to 0
while(!(feof($fp))) // While not end of file
{
$buffer=fgets($fp,4096); // Get content
$count+=1; // Increment
$buffer=str_replace(Chr(13).Chr(10),"",$buffer); // Remove new ine

if($buffer==$ip) // If IP already exists
{
$found=true; // Set found to true
break; // Stop the loop
} // End of if statement
} // End of the while loop
fclose($fp); // Closes the connection

$fp=fopen('ip.txt','a'); // @param1 - Open a file with name ip.txt. @param2- argument. Read documentation
if(!$found) // If found
fwrite($fp,$ip.chr(13).chr(10)); // Write the IP on ip.txt
fclose($fp); // Close the connection


Ensure ip.txt exist.

Hope that helps (This is what I'm using on my sites).

sethberno
11-21-2008, 02:11 AM
okay, so just add that text to the page i want the IP's recorded from and it will record to the ip.txt file? just making sure, i am thinking thats how it is done. let me know if i am wrong. Also, thank you SO much for your help!

rangana
11-21-2008, 02:59 AM
Yes, just create a file named ip.txt and all are set.

sethberno
11-21-2008, 03:09 AM
other than it not working at all... its perfect. :-/

I have it on a page within my forum... and when i go to it .... it logs nothing.

rangana
11-21-2008, 08:06 AM
Ensure that the script and ip.txt is in the same folder. Else you need to change highlighted as to the location of your file:


$found=false; // Initialize found to false
$ip=$_SERVER['REMOTE_ADDR']; // Get visitor's IP address
$fp=fopen('ip.txt','r'); // @param1 - Open a file with name ip.txt. @param2- argument. Read documentation
$count=0; // Initialize count var to 0

sethberno
11-26-2008, 05:08 PM
does it have to be in the root folder? or anywhere on my server?

As long as both those files are in the right area it should be alright, correct?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum