我正在使用本教程跟踪工具,我得到了它的工作。我正在尝试对其进行修改以满足我的需求,以跟踪 Verizon Wirless(我的手机连接)以观察他们何时开始限制我的 ip 更改。我哥哥有 AT&T,所以我在我的数据库中添加了一个主机名字段,这样我们就可以区分我们的手机......但可以让它显示在 IP 旁边的报告页面中。当我单击视图以显示我访问过的页面时,我可以在其中显示它,但不能在主页上显示,如果有人能够指出它不显示的原因或我更改错误的原因,这是我的代码
只是提到注意到两个已删除的帖子...我不跟踪任何人但我自己,,, 我在 verizon 无线上有一个根深蒂固的迅雷,,, 一旦我在一天内达到 4 gig 数据 (仍然有无限计划) verizon喜欢从一个 IP 启动我,然后将我切换到另一个更慢的 IP,我试图找出我注意到哪些 IP 带宽更好,所以我可以循环无线电,直到它再次恢复正常
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>