IP Logger menu

User Tag List

Thread: IP Logger

Results 1 to 13 of 13
  1. #1
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IP Logger

    A simple little PHP script to log IPs along with a datestamp of when they were logged. Yep, that simple.

    Code:
    <?php
        $file_name = ('./ip_log.txt');
        $time = date("d/m/Y h:i A" ,time());
        $ip = $_SERVER['REMOTE_ADDR'];
        $fp = fopen($file_name, "a");
        fwrite($fp, "IP: ".$ip." - Time: ".$time."\n");
        fclose($fp);
    ?>
    If you want to be a LITTLE fancier, you can make it deny access to the file when they try and access it.

    Code:
    <?php
        $file_name = ('./ip_log.php');
        $time = date("d/m/Y h:i A" ,time());
        $ip = $_SERVER['REMOTE_ADDR'];
     
        if(!file_exists($file_name)){
        $fp = fopen($file_name, "w");
        fwrite($fp, "<?php die('Oi! This file is private! No peeking!');?>");
        fclose($fp);}
     
        $fp = fopen($file_name, "a");
        fwrite($fp, "IP: ".$ip." - Time: ".$time."\n");
        fclose($fp);
    ?>
    Enjoy!

    IP Logger
  2. #2
    Zeluous's Avatar Active Member
    Reputation
    61
    Join Date
    Dec 2008
    Posts
    423
    Thanks G/R
    0/3
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont have a need for this nor do I really get it, But I know it will be useful for some people :P +rep

  3. #3
    2dgreengiant's Avatar ★ Elder ★


    Reputation
    1192
    Join Date
    Feb 2007
    Posts
    7,129
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did need this haha thanks <3
    If you need me you have my skype, if you don't have my skype then you don't need me.

  4. #4
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know you needed it, 2d Hence why it was written, then you didn't need it any more lol.

  5. #5
    bsod-staff14's Avatar Member
    Reputation
    35
    Join Date
    Nov 2008
    Posts
    443
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like it +Rep but maybe should make it so it inserts it into a db I will come back with a edit on how to do it .
    Immortal GamerZ Under Development!

  6. #6
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could change it to write to a DB, but that would take a little bit more time. Not much, but a little. This is just a quick script thrown together in a few minutes. Though it could be useful if your host didn't give you a db.

  7. #7
    bsod-staff14's Avatar Member
    Reputation
    35
    Join Date
    Nov 2008
    Posts
    443
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True true . But I was talking in the case of security purposes for a website
    Immortal GamerZ Under Development!

  8. #8
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's merits to both ways. DB for security, file for less needs.

  9. #9
    bsod-staff14's Avatar Member
    Reputation
    35
    Join Date
    Nov 2008
    Posts
    443
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gawd beat me again :P.
    Immortal GamerZ Under Development!

  10. #10
    inzenir's Avatar Member
    Reputation
    9
    Join Date
    Aug 2009
    Posts
    52
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, not that bad script, but could be done better. I would do it like this:

    I would store IP as long int and time as standard time, so it's more flexible and faster to transform in the output. Storing as int makes the script faster because having number takes less memory space than having a string.

    PHP Code:
        //well, this should bypass proxies and stuff in theory, didn't try in RL :P
        
    if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip getenv("HTTP_CLIENT_IP");
        elseif (
    getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip getenv("HTTP_X_FORWARDED_FOR");
        elseif (
    getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip getenv("REMOTE_ADDR");
        elseif (isset(
    $_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip $_SERVER['REMOTE_ADDR'];
        else 
    $ip "unknown";
        
        
    //we'll store IP as long int, so we can store it as a number into the database
        
    if ($ip != "unknown")
            
    $ip ip2long($ip); //we transform ip from something like 127.0.0.1 to something like 2130706433
            
    die("Could not retrieve IP."); //we certainly don't want someone with no visible IP to be on our page, so we "die"
        
        
    $query 'INSERT INTO log(ip, time) VALUES ('.$ip.', '.time().')';
        
    mysql_query($query) or die(mysql_error().'<br />'.$query); //we insert values to database or die with error 

  11. #11
    UnknownHero's Avatar Member
    Reputation
    3
    Join Date
    Dec 2008
    Posts
    11
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Inzenir,
    you should think of,
    (sanitize,)-(secure mysql queries),
    and also u should read up on how to stack your code,
    if,
    elseif
    elseif
    elseif
    else
    first of all you could use switch instead.

    just saying.

    /UH
    Last edited by UnknownHero; 11-15-2009 at 02:49 AM. Reason: more txt

  12. #12
    Dixo1's Avatar Member
    Reputation
    1
    Join Date
    Jun 2008
    Posts
    22
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haha nice one :-D Might going to use this logger for my website. Just in a pimped version :-D

  13. #13
    GrooN's Avatar Banned
    Reputation
    7
    Join Date
    Sep 2006
    Posts
    68
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fine piece of work, but another way to make sure people doesn't read it would be to set the permission of the file to 660. Either by using chmod(), or just ftp.
    Another way to do it, would be to throw in a 404 header error followed by an exit

    Code:
    <?php
    header("HTTP/1.0 404 Not Found");
    exit;
    ?>
    Last edited by GrooN; 01-07-2010 at 12:54 PM.

Similar Threads

  1. Key logger
    By SmotPoker in forum World of Warcraft General
    Replies: 2
    Last Post: 03-20-2008, 03:25 AM
All times are GMT -5. The time now is 02:36 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search