PHP question.....

Discussion in 'OT Technology' started by Little Spunky $#!T, Mar 24, 2004.

  1. Little Spunky $#!T

    Little Spunky $#!T :cool:

    Joined:
    Jul 16, 2001
    Messages:
    3,539
    Likes Received:
    0
    I have a simple "hidden" tracker that I use for several of my webpages. The tracker records the visitors IP and some other little info. I want this tracker to block my home's IP address. I don't want it to count my IP address since I'm not a 'real' visitor so I can get a more honest count.

    Here is an example of what the tracker does:

    [​IMG]

    Here is the code for the tracker (php):
    Code:
    <!--
    Copyright (C) 2002  Andrew Wilkes [email][email protected][/email]
    
    Logger for website visitor tracking.
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    [url]http://www.gnu.org/licenses/gpl.html[/url]
    
    -->
    <?php
    
    // CUSTOMIZATION
    $password="----"; // the password to view stats
    $maxlines = 1000; // the maximum number of lines to show
    $fn = "log.txt"; // the name of the log file to create
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Urgentclick.com - Website Visitor Tracker</title>
    </head>
    <body><font face="arial, helvetica, sans-serif">
    <?php
    // create new file
    $fp = fopen ($fn, "r");
    if (!$fp) {
       $fp = fopen ($fn, "w");
       if ( $fp ) {
       	  $os = "0\r\n";
       	  $fw = fwrite($fp, $os);
    	  fclose($fp);
       }
    } else {
       fclose($fp);
    }
    
    // read existing data
    $fa = file($fn);
    $nl = count($fa);
    
    if (isset($page)) {
    $c = $fa[0] + 1; // inc hit
    
    // write data to file
    $fp = fopen ($fn, "w");
    $os = $c . "\r\n";
    $fr = fwrite($fp,$os);
    $ip = getenv("REMOTE_ADDR");
    $os = $page . "</td><td>" . date("D M jS g:ia") . "</td><td>" . $ip . "</td><td>" . $ref . "\r\n";
    $fr = fwrite($fp,$os);
    if ($nl > $maxlines) { $nl = $maxlines; }
    if ($nl > 1) {
       for ($i = 1; $i < $nl; $i++)
       	  $fr = fwrite($fp,$fa[$i]); 
    }
    fclose($fp);
    
    } else {
    // output results
    
    if (!isset($pass) ) { $pass=""; }
    
    if ($pass != $password) {
    // get password
    echo "
    <form action=\"tracker.php\">
    <p>Enter password: <input name=\"pass\" type=\"password\" value=\"\"><input type=\"submit\"></p>
    </form>\n";
    
    } else {
    echo "<h1>Visitor Traffic Report</h1><p><hr><font-size:7px><b>Ignore</b></font> the IP address that starts with 66.82.9.??. That is your IP.<hr><p><b>Total hits:</b> $fa[0]</p>
    <table cellpadding=10><tr><td><b>Page</b></td><td><b>Date/Time</b></td><td><b>Visitor IP</b></td><td><b>Referring Page (blank if blocked or direct)</b></td></tr>\r\n";
    if ($nl > 1) {
       for ($i = 1; $i < $nl; $i++)
       	  echo "<tr><td>$fa[$i]</td></tr>\n"; 
    }
    echo "</table>\n";
    }
    }
    ?>
    <hr>
    <p>From <b>www.urgentclick.com</b> <a href="http://www.urgentclick.com">More Webmaster Resources</a></p>
    </font></body></html>
    
    The tracker.php then writes the result to "log.txt"
     
  2. Ximian

    Ximian New Member

    Joined:
    Mar 20, 2004
    Messages:
    1,860
    Likes Received:
    0
    Location:
    DCA
    // write data to file
    $fp = fopen ($fn, "w");
    $os = $c . "\r\n";
    $fr = fwrite($fp,$os);
    $ip = getenv("REMOTE_ADDR");


    if ($ip == "127.0.0.1" || "192.168.x.x")
    {
    add code to go to fpclose and quit
    }
    else
    // everything below
     
  3. Little Spunky $#!T

    Little Spunky $#!T :cool:

    Joined:
    Jul 16, 2001
    Messages:
    3,539
    Likes Received:
    0
    I tried to put that in there but I got errors. Could you please just put it into that whole script and post it as a code and I'll copy and paste that. I must of done something wrong.

    Thanks
     
  4. Ximian

    Ximian New Member

    Joined:
    Mar 20, 2004
    Messages:
    1,860
    Likes Received:
    0
    Location:
    DCA
    I was just using that as an example as to what YOU can do. If you don't know PHP, I can code that example tomorrow for you, if I find time or if someone else is nice enough to do it...

    Seriously though, consider getting something better to similar things, like awstats or webalizer if you have access to the web server's access logs.
     
  5. Little Spunky $#!T

    Little Spunky $#!T :cool:

    Joined:
    Jul 16, 2001
    Messages:
    3,539
    Likes Received:
    0
    Alright--well I have webalizer but I one of the main things I want to block thats bein counted is my IP. Is it possible to do this with my webalizer?
    http://upload.railegelbvieh.com/webalizer
     
  6. Ximian

    Ximian New Member

    Joined:
    Mar 20, 2004
    Messages:
    1,860
    Likes Received:
    0
    Location:
    DCA
    Enter at bottom of webalizer.conf:

    To hide your own site, do "HideReferrer siteaddress" or "IgnoreReferrer siteaddress" and I think "IgnoreSite IPaddress" should block your IP address, just make sure you put in all of them.

    Run webalizer again and delete the history file if you have one.
     
  7. Little Spunky $#!T

    Little Spunky $#!T :cool:

    Joined:
    Jul 16, 2001
    Messages:
    3,539
    Likes Received:
    0
    Is all I have is a webalizer.hist and a webalizer.current --- no webalizer.conf.

    And shouldn't I have to tell it which IP address to block? How can it automatically know my home IP?
     
  8. Ximian

    Ximian New Member

    Joined:
    Mar 20, 2004
    Messages:
    1,860
    Likes Received:
    0
    Location:
    DCA
    For "siteaddress" and "IPaddress" replace it with your own settings and webalizer.conf should be where webalizer.exe is. If this isn't on Windows, just use 'locate' but make sure to 'updatedb' first.

    Should be either in /etc or /usr/local/etc
     
  9. Little Spunky $#!T

    Little Spunky $#!T :cool:

    Joined:
    Jul 16, 2001
    Messages:
    3,539
    Likes Received:
    0
    Well the webalizer came with my hosting account, I didn't install it myself. Should I download the recent one and install it? Because I've searched the entire folder on my server and its not there.
     
  10. Little Spunky $#!T

    Little Spunky $#!T :cool:

    Joined:
    Jul 16, 2001
    Messages:
    3,539
    Likes Received:
    0
  11. Ximian

    Ximian New Member

    Joined:
    Mar 20, 2004
    Messages:
    1,860
    Likes Received:
    0
    Location:
    DCA
    No, look for webalizer.conf, it's in the same place as webalizer.exe. It might also be named sample-webalizer.conf or something along those lines, look for it. The "configure" file is something much different.
     

Share This Page