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 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is there a scipt that logs IP adresses of visitors in a .TXT File?

    Hello,
    I really wanna know a php script that logs the ip adresses of visitors into a .TXT file on the website. I searched around these forums and tried the search engine but didn't found what i wanted. Please help me.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?php
    $file 
    "iplog.txt";
    $ip $_SERVER['REMOTE_ADDR'];

    if(
    is_writable($file)){
      
    $open fopen($file,"a");
      
    fwrite($open,$ip);
      
    fclose($open);
    }else{
      
    chmod($file,0777) or die("Attempted to chmod the file, it was unsuccessful, please chmod ".$file." to 0777 yourself");
      echo 
    'File was unwritable. Please refresh the page to try again';
    }
    ?>
    Put that at the top of the page you want to log the ip's on
    Last edited by Nightfire; 01-03-2004 at 05:49 PM.

  • #3
    New Coder
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks! but i also found this:
    PHP Code:
    ?php 

    $filename
    "hits.txt" 

    $fd fopen ($filename "r") or die ("Uhoh! The PHP script cant open $filename") ; 

    $fstring fread ($fd filesize ($filename)) ; 

    echo 
    "$fstring" 

    fclose($fd) ; 



    $fd fopen ($filename "w") or die ("Uhoh! The PHP script cant open $filename") ; 

    $fcounted $fstring 

    $foutfwrite ($fd $fcounted ) ; 

    fclose($fd) ; 

    ?> 

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Well that's not logging IP's of visitors, that's a hit counter.

  • #5
    New Coder
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Welllll

    Then i got the wrong code from a guy. I had my doubts already, for not containing REMOTE_ADDR thing.


  •  

    Posting Permissions

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