Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Record IP script??

    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!

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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:
    PHP Code:
    $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).
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    sethberno (11-21-2008)

  • #3
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Yes, just create a file named ip.txt and all are set.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.
    Last edited by sethberno; 11-21-2008 at 04:28 AM.

  • #6
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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:
    Code:
    $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
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #7
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •