I am using this tutorial Tracking Tool, I got it working. I’m trying to modify it to fit my needs, in tracking Verizon Wirless (my cell connection) to watch when they start throttling me my ip changes. My older brother has AT&T so I’v added in my database a hostname field so we can distinguish between our phones.. but can get it to display in the report page next to the IP. When I click on the view to show what pages I have visited I can display it in there but not on the main page, heres my code if anyone might be able to point out the reason why its not displaying or what I’m changing wrong
Just to mention noticed two posted deleted… I”M NOT TRACKING ANYONE BUT MYSELF,,, i have a rooted thunderbolt on verizon wirless,,, once i hit 4 gig of data in a day(still have the unlimited plan) verizon likes to boot me off of one IP and switch me to another thats slower, I’m trying to pin point which IPs i notice better bandwidth on, so i can cycle the radios until it gets back on a good one again
MySQL
DROP TABLE IF EXISTS `testing_db`;
CREATE TABLE IF NOT EXISTS `testing_db` (
`entry_id` INT(11) NOT NULL AUTO_INCREMENT,
`visitor_id` INT(11) DEFAULT NULL,
`ip_address` VARCHAR(15) NOT NULL,
`hostname` VARCHAR(295) NOT NULL,
`server_name` text,
`useragent` text,
`page_name` text,
`query_string` text,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`entry_id`),
KEY `visitor_id` (`visitor_id`,`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ip_tracker.php
<?php
//define our "maximum idle period" to be 30 minutes
$mins = 1;
//set the time limit before a session expires
ini_set ("session.gc_maxlifetime", $mins * 60);
session_start();
$ip_address = $_SERVER["REMOTE_ADDR"];
$page_name = $_SERVER["SCRIPT_NAME"];
$query_string = $_SERVER["QUERY_STRING"];
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$host_name = $hostname; //$_SERVER['HTTP_HOST'];
$server_name = $_SERVER['SERVER_NAME'];
$useragent=$_SERVER['HTTP_USER_AGENT'];
$current_page = $page_name."?".$query_string;
//connect to the database using your database settings
include("db_connect.php");
if(isset($_SESSION["tracking"])){
//update the visitor log in the database, based on the current visitor //id held in $_SESSION["visitor_id"]
$visitor_id = isset($_SESSION["visitor_id"])?$_SESSION["visitor_id"]:0;
if($_SESSION["current_page"] != $current_page){
$sql = "INSERT INTO testing_db
(ip_address, page_name, query_string, visitor_id, hostname, host_name, server_name, useragent)
VALUES ('$ip_address', '$page_name', '$query_string', '$visitor_id','$hostname','$host_name','$server_name','$useragent')";
if(!mysql_query($sql)){
echo "Failed to update visitor log";
}
$_SESSION["current_page"] = $current_page;
}
$_SESSION["tracking"] = false;
}else{
//set a session variable so we know that this visitor is being tracked
//insert a new row into the database for this person
$sql = "INSERT INTO testing_db
(ip_address, page_name, query_string, visitor_id, hostname, host_name, server_name, useragent)
VALUES ('$ip_address', '$page_name', '$query_string', '$visitor_id','$hostname','$host_name','$server_name','$useragent')";
if(!mysql_query($sql)){
echo "Failed to add new visitor into tracking log";
$_SESSION["tracking"] = false;
} else {
//find the next available visitor_id for the database
//to assign to this person
$_SESSION["tracking"] = true;
$entry_id = mysql_insert_id();
$lowest_sql = mysql_query("SELECT MAX(visitor_id) as next FROM testing_db");
$lowest_row = mysql_fetch_array($lowest_sql);
$lowest = $lowest_row["next"];
if(!isset($lowest))
$lowest = 1;
else
$lowest++;
//update the visitor entry with the new visitor id
//Note, that we do it in this way to prevent a "race condition"
mysql_query("UPDATE testing_db SET visitor_id = '$lowest' WHERE entry_id = '$entry_id'");
//place the current visitor_id into the session so we can use it on
//subsequent visits to track this person
$_SESSION["visitor_id"] = $lowest;
//save the current page to session so we don't track if someone just refreshes the page
$_SESSION["current_page"] = $current_page;
ip_report.php
<?php
include("db_connect.php");
//retrieve the appropriate visitor data
$view = $_GET["view"];
//set a default value for $view
if($view!="all" && $view!="record")
$view = "all";
if($view == "all")
{
//show all recent visitors
$sql = "SELECT visitor_id, GROUP_CONCAT(DISTINCT ip_address) as ip_address_list,
COUNT(DISTINCT ip_address) as ip_total, COUNT(visitor_id) as page_count,
MIN(timestamp) as start_time, MAX(timestamp) as end_time FROM testing_db GROUP BY visitor_id";
$result = mysql_query($sql);
if($result==false){
$view = "error";
$error = "Could not retrieve values";
}
} else {
//show pages for a specific visitor
$visitor_id = $_GET['id'];
//rung $visitor_id through filter_var to check it's not an invalid
//value, or a hack attempt
if(!filter_var($visitor_id, FILTER_VALIDATE_INT, 0)){
$error = "Invalid ID specified";
$view = "error";
} else {
$sql = "SELECT timestamp, page_name, query_string, ip_address, hostname, host_name, server_name, useragent FROM
testing_db WHERE visitor_id = '$visitor_id'";
$result = mysql_query($sql);
}
}
function display_date($time){
return date("F j, Y, g:i a", $time);
}
?>
<html>
<head>
<title>IP Tracker Report Page</title>
<style>
html {font-family:tahoma,verdana,arial,sans serif;}
body {font-size:62.5%;}
table tr th{
font-size:0.8em;
background-color:#ddb;
padding:0.2em 0.6em 0.2em 0.6em;
}
table tr td{
font-size:0.8em;
background-color:#eec;
margin:0.3em;
padding:0.3em;
}
</style>
</head>
<body>
<h1>IP Tracker Report</h1>
<?php if($view=="all") {
//display all of the results grouped by visitor
if($row = mysql_fetch_array($result)){
?>
<table>
<tbody>
<tr>
<th>Id</th>
<th>IP Address(es)</th>
<th>Host Name</th>
<th>Entry Time</th>
<th>Duration</th>
<th>Pages visited</th>
<th>Actions</th>
</tr>
<?php
do{
if($row["ip_total"] > 1)
$ip_list = "Multiple addresses";
else
$ip_list = $row["ip_address_list"];
$start_time = strtotime($row["start_time"]);
$end_time = strtotime($row["end_time"]);
$start = display_date($start_time);
$end = display_date($end_time);
$duration = $end_time - $start_time;
if($duration >= 60) {
$duration = number_format($duration/60, 1)." minutes";
}
else {
$duration = $duration." seconds";
}
$host - $row["hostname"];
echo "<tr>";
echo "<td>{$row["visitor_id"]}</td>";
echo "<td>$ip_list</td>";
echo "<td>$host</td>";
echo "<td>$start</td>";
echo "<td>$duration</td>";
echo "<td>{$row["page_count"]}</td>";
echo "<td><a href='ip_report.php?view=record&id={$row["visitor_id"]}'>view</a></td>";
echo "</tr>";
} while ($row = mysql_fetch_array($result));
?>
</tbody>
</table>
<?php } else { ?>
<h3>No records in the table yet</h3>
<?php } ?>
<?php } elseif($view=="record"){ ?>
<h3>Showing records for Visitor <?php echo $visitor_id; ?></h3>
<p><a href="ip_report.php">back</a></p>
<?php
//show all pages for a single visitor
if($row = mysql_fetch_array($result)){
?>
<table>
<tbody>
<tr>
<th>Page viewed</th>
<th>User Agent</th>
<th>Time of view</th>
</tr>
<?php
do{
if($row["ip_total"] > 1)
$ip_list = "More than 1";
else
$ip_list = $row["ip_address_list"];
$time = display_date(strtotime($row["timestamp"]));
echo "<tr>";
echo "<td>{$row["page_name"]}</td>";
echo "<td>{$row["hostname"]}</td>";
echo "<td>$time</td>";
echo "</tr>";
} while ($row = mysql_fetch_array($result));
?>
</tbody>
</table>
<?php } else { ?>
<h3>No records for this visitor</h3>
<?php
}
} elseif($view=="error") { ?>
<h3>There was an error</h3>
<?php echo $error;
}
?>
</body>
</html>
Add this last line to your report script: