1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Advanced IP Logger (IP Address, Refer Page, Current Page + More!)

Discussion in 'PHP & Perl' started by TechnicalSergio, May 29, 2010.

  1. TechnicalSergio

    TechnicalSergio Newbie

    Joined:
    Jan 19, 2010
    Messages:
    32
    Likes Received:
    80
    Occupation:
    Stackin' Paper
    Location:
    San Jose
    Home Page:
    Logs Records Of:
    * IP Address
    * Refer Page
    * Current Page
    * Local Date
    * Local Time
    * User Agent

    Example of a Log:
    Code:
    [B]Wednesday 11 November 2009 10:10pm[/B]
    [B]IP:[/B] 82.3.557.17
    [B]Page:[/B] /test.php
    [B]Refer:[/B] [URL]http://www.randomsite.com/forum.php?=24924[/URL]
    [B]Useragent: [/B]Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
    advancedtracking.php

    Code:
    <?php
    $log = 'log.html';
    $ip = $_SERVER['REMOTE_ADDR'];
    $page = $_SERVER['REQUEST_URI'];
    $refer = $_SERVER['HTTP_REFERER'];
    $date_time = date("l j F Y  g:ia", time() - date("Z")) ;
    $agent = $_SERVER['HTTP_USER_AGENT'];
    $fp = fopen("log.html", "a");
    fputs($fp, "
    <b>$date_time</b> <br> <b>IP: </b>$ip<br><b>Page: </b>$page<br><b>Refer: </b>$refer<br><b>Useragent: 
    
    </b>$agent <br><br>
    ");
    flock($fp, 3); 
    fclose($fp);
    ?>
     
  2. Googler

    Googler Junior Member

    Joined:
    Apr 15, 2009
    Messages:
    157
    Likes Received:
    190
    Occupation:
    Black Hat Advanced Ninga Trainer
    Location:
    3D World
    Between below one detects real ip If they use proxy

    PHP:


    <?php
    // Dev Googler of BHW added Real IP Function 

    function getRealIpAddr()
    {
        if (!empty(
    $_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
        
    {
          
    $ip=$_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (!empty(
    $_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
        
    {
          
    $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        else
        {
          
    $ip=$_SERVER['REMOTE_ADDR'];
        }
        return 
    $ip;
    }

    $realip getRealIpAddr();
    $log 'log.html';
    $ip $_SERVER['REMOTE_ADDR'];
    $page $_SERVER['REQUEST_URI'];
    $refer $_SERVER['HTTP_REFERER'];
    $date_time date("l j F Y  g:ia"time() - date("Z")) ;
    $agent $_SERVER['HTTP_USER_AGENT'];
    $fp fopen("log.html""a");
    fputs($fp"
    <b>
    $date_time</b> <br> <b>IP: </b>$ip<br><b>IP: </b>$realip<br><b>Page: </b>$page<br><b>Refer: </b>$refer<br><b>Useragent: 

    </b>
    $agent <br><br>
    "
    );
    flock($fp3); 
    fclose($fp);
    ?>

     
  3. _Chip_

    _Chip_ Senior Member

    Joined:
    Jun 28, 2009
    Messages:
    847
    Likes Received:
    256
    Occupation:
    Student
    Location:
    Depends on my vpn
    wow .. real ip !! :O thats cool !
     
  4. lowridertj

    lowridertj Newbie Premium Member

    Joined:
    Apr 13, 2008
    Messages:
    45
    Likes Received:
    24
    port 80 and port 8080 proxys will be seen as a real ip regardless of the above.
     
  5. stargazerrrrr

    stargazerrrrr Newbie

    Joined:
    Nov 18, 2010
    Messages:
    3
    Likes Received:
    0
    Here is a simple script to distinguish bots and users:

    Code:
    
    //Here is sql for mysql db:
    
    CREATE TABLE `bot_ips` (
      `id` int(11) NOT NULL auto_increment,
      `ip` varchar(25) NOT NULL,
      `bot` varchar(100) NOT NULL,
      PRIMARY KEY  (`id`),
      UNIQUE KEY `ipi` (`ip`)
    ) ENGINE=MyISAM
    
    //Fill db with ip:
    
    mysql_connect("localhost","root","");
    mysql_select_db("mydatabase");
    
    $ips = array(
    'google' => 'hxxp://iplistsdotcom/nw/google.txt',
    'msn' => 'hxxp://iplistsdotcom/nw/msn.txt',
    );
    
    foreach ($ip_list as $bot => $ip_url) {
    
        $strs = file($ip_url);
        for($i = 0; $i < count($strs); $i++ )
        {
            if( $strs[$i][0] == '#' ) continue;
            $str = trim($strs[$i],"\r\n ");
            mysql_query("INSERT IGNORE INTO bot_ips SET ip = '".mysql_real_escape_string($str)."', bot = '".$bot."'");
        }
    
    }
    
    //This function returns the name of bot or NULL if user
    
    function isBot()
    {
        if( empty($_SERVER['REMOTE_ADDR']) ) return false;
    
        $res = mysql_query("SELECT bot FROM bot_ips WHERE '".$_SERVER['REMOTE_ADDR']."' LIKE CONCAT(ip,'%') LIMIT 0,1");
        $row = mysql_fetch_assoc($res);
    
        if( empty($row) ) return false;
    
        return $row['bot'];
    }
    
     
  6. daltarak

    daltarak Newbie

    Joined:
    Oct 4, 2009
    Messages:
    22
    Likes Received:
    3
    Why you don't use the Apache's LogFormat directive? You can get any header you want with it. For example you can use "%{HTTP_X_FORWARDED_FOR}i" to get HTTP_X_FORWARDED_FOR value.

    Also its always hard to parse multi-lined log files, just use a single line per request so later you can get anything you want with a single grep & awk combination.

    I'm not trolling, just trying to help.