SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple IP Logger?

    Hi again.. I've tried the PHP Freaks code snippet and it doesnt log anything... Could someone tell me how to log an IP to a .txt file with the respective date and time they viewed the site without using mysql, if it can't be done without mysql could you tell me the sql code to enter into my database on myPHPAdmin.

    Best Regards,
    imati0n

    Thank you

  2. #2
    SitePoint Zealot Saj's Avatar
    Join Date
    May 2003
    Location
    USA
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could do this:

    PHP Code:
    $ip getenv("REMOTE_ADDR");
    $file fopen("ip.txt""a");
    fwrite ($file$ip);
    fclose($file); 

  3. #3
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that... The ip.txt file comes up empty, even after chmodding it correctly.

    Thanks though

  4. #4
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind... Found a tutorial. Here's the code:

    PHP Code:
     <?php
     $addr
    =$REMOTE_ADDR// Assigns Remote address to $addr
     
    $server=$SERVER_NAME// Assigns Server Name to $server
     
    $today=date("d/M/Y:H:i:s"); // Assigns the date details to $today
     
    $timecorr="+0530"//  Provides Offset for time zone + or - from GMT :: +0530 for India
     
    $method=$REQUEST_METHOD// Assigns the Method to $method
     
    $serprot=$SERVER_PROTOCOL// Assigns the Protocol to $serprot
     
    $browser=$HTTP_USER_AGENT// Assigns Browser details to $browser
     
    $space=" "//  Assigns space to $space
     
    $apos='"'// Assigns " to $apos
     
    $fil=$SCRIPT_NAME// Assigns the called file along with path to $fil
     
    $name=basename($fil); //  Uses basename() to get the file name from path with file name
     
    $fsiz=filesize($name); // Uses filesize() to get size of file $name
     
    $ref=$HTTP_REFERER// Assigns the referring file to $ref
     // All the special characters like - , [ ] ," and spaces to meet format needs are achieved below.
     // when the string $webdet is created.
     
    $webdet=$addr.$space.$server." - "."[".$today.$space.$timecorr."]".$space.$apos.$method.$space.$fil.$space.$serprot$apos.$space."200".$space.$fsiz.$space.$apos.$ref.$apos.$space.$apos.$browser.$apos."\n";
      
    // The string $webdet with all the parts is created using the string operator . to join the
      // different individual elements, with a end of line "\n" at the end of the string
     
    $filelog="ip.txt"// Assigns file ip.txt to $filelog
     
    $fweb=fopen($filelog,"a"); // Opens a file pointer $fweb
     
    fputs($fweb,$webdet,250); // Appends the entire string up to 250 bytes length to the file
     
    fclose($fweb); // Closes the file after writing
     
    ?>
    Add ip.txt to the folder where this will be located and chmod it to 777, i would include() this in my index.php =)

  5. #5
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heysa, where did you find that script?

  6. #6
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forgot =/

  7. #7
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no worries, it's working good for ya though?

  8. #8
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah.... The logs look like this:

    Code:
     68.51.162.105 http://www.liquidfridge.net - [19/May/2003:20:35:39 +0530] "GET /sigs/index.php HTTP/1.1" 200 4264 "" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"


Bookmarks

Posting Permissions

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