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 3 of 3
  1. #1
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts

    Recording to text file

    Hello,

    When ever a visitor goes to my site I would like a .php script write to a text (.txt) file with the following information about the visitor:

    IP address
    Browser and OS
    Their local time

    I then can go to the text file and take a look at the info. If someone can help that would be great. Thanks


    Leonard Whistler
    www.stubby.ca

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Untested and just written in here, but it should work

    (see http://php.net/fwrite for more examples)

    The file you need to create and chmod to 0777 is called log.txt and put the php below into your php page
    PHP Code:
    <?php
    $filename 
    "log.txt";

    $somecontent $_SERVER['REMOTE_ADDR']." :: ".$_SERVER['HTTP_USER_AGENT']." :: ".date ("l dS of F Y h:i:s A").
    "\n";

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

        
    // In our example we're opening $filename in append mode.
        // The file pointer is at the bottom of the file hence 
        // that's where $somecontent will go when we fwrite() it.
        
    if (!$handle fopen($filename'a')) {
             print 
    "Cannot open file ($filename)";
             exit;
        }

        
    // Write $somecontent to our opened file.
        
    if (!fwrite($handle$somecontent)) {
            print 
    "Cannot write to file ($filename)";
            exit;
        }
        
        print 
    "Success, wrote ($somecontent) to file ($filename)";
        
        
    fclose($handle);
                        
    } else {
        print 
    "The file $filename is not writable";
    }
    ?>
    Getting their timezone is a little tricky, see the thread of zoobie's for more info http://www.codingforums.com/showthre...threadid=26898

    The time put on the file is the time from your server, not their time, unless they're in the same timezone as your server is.
    Last edited by Nightfire; 09-29-2003 at 02:45 AM.

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Nightfire..thanks for the help.


    Leonard Whistler
    www.stubby.ca


  •  

    Posting Permissions

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