 |
|
|
12-18-2008, 02:32 AM
|
Tracking System
|
Posts: 72
Location: singapore
|
hi.. is there any simple script for me to track URL clicks on my website?
and display the database on a page...
|
|
|
|
12-18-2008, 03:34 AM
|
Re: Tracking System
|
Posts: 843
Name: Mike
Location: United Kingdom
|
Yes, put in the link a variable like
nextpage.php?from=pagetheywerefrom
then just add the $_GET['from'] bit into a database.
If you want to track where people come from, check your logs (If you have cPanel, there is an icon for called "latest visitors")
__________________
My Blog/Site: Please login or register to view this content. Registration is FREE
|
|
|
|
12-18-2008, 07:10 AM
|
Re: Tracking System
|
Posts: 203
Name: Andy
Location: N.Ireland
|
Hi,
Are you talking about the referral or the path they use when they visit your website? If you're referring to the path, I'm pretty sure data protection forbids you from publishing that if it's in anyway indentifiable, you can keep that information to yourself personally to track user trends.
I would use Google Analytics if I where you.. http://www.google.com/analytics
It has some great reporting tools..
Thanks,
Andy
|
|
|
|
12-18-2008, 11:51 AM
|
Re: Tracking System
|
Posts: 72
Location: singapore
|
Google is definitely best solution.. however for some reason.. i am not allow to use Goooooogle..
any tutorials around??? for such script???
i have found a article on http://www.devpapers.com/article/345
but is it possible to track every menu links???
|
|
|
|
12-18-2008, 12:14 PM
|
Re: Tracking System
|
Posts: 203
Name: Andy
Location: N.Ireland
|
Hi,
That bit of code should do exactly what you need, if you're expecting high traffic load, I would recommend using a MySQL database to store the database as opposed to the text file option they have provided there...
PHP Code:
<?PHP $ipaddress = $_SERVER['REMOTE_ADDR']; $page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"; $page .= iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", ""); $referrer = $_SERVER['HTTP_REFERER']; $datetime = mktime(); $useragent = $_SERVER['HTTP_USER_AGENT']; $remotehost = @getHostByAddr($ipaddress); ?>
Then create a database called logs or something similar.. create your tables to match your variables above
ipaddress
page
referrer
datetime
useragent
remotehost
attach the following code to your page to insert the information to the database...
PHP Code:
<?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); mysql_query("INSERT INTO logs (ipaddress, page, referrer, datetime, useragent, remotehost) VALUES ('$ipaddress','$page','$referrer','$datetime','$useragent','$remotehost)"); mysql_close($con); ?>
Then you'll need to pull the information from the database
PHP Code:
<? $dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("databasename");
?>
<?
if(isset($_POST['ipaddress'])){ $ipaddress = $_POST['ipaddress']; } else { $ipaddress=""; } ?>
<?
if(isset($_POST['page'])){ $page = $_POST['page']; } else { $page=""; } ?>
<?
if(isset($_POST['referrer'])){ $referrer = $_POST['referrer']; } else { $referrer=""; } ?>
<?
if(isset($_GET['datetime'])){ $datetime = $_GET['datetime']; } else { $datetime=""; } ?>
<?
if(isset($_GET['useragent'])){ $useragent = $_GET['useragent']; } else { $useragent=""; } ?>
<?
if(isset($_GET['remotehost'])){ $remotehost = $_GET['remotehost']; } else { $remotehost=""; } ?>
<?
$sql="SELECT * FROM logs ORDER BY id DESC"; $result=mysql_query($sql); $ncount=0; while ($myrow=mysql_fetch_array($result)) { if ($ncount<60) { $ncount=$ncount+1; ?>
<? if(isset($myrow['ipaddress'])) echo $myrow['ipaddress']; ?> <Br> <? if(isset($myrow['page'])) echo $myrow['page']; ?>
<? } ?>
That should work, although I haven't tested it...
Andy
|
|
|
|
12-23-2008, 09:18 AM
|
Re: Tracking System
|
Posts: 72
Location: singapore
|
HI i am using the code here.. however how do i add a column for to log number of visitors visited that page...
Quote:
CREATE TABLE `visitors_table` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`visitor_ip` VARCHAR( 32 ) NULL ,
`visitor_browser` VARCHAR( 255 ) NULL ,
`visitor_hour` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_minute` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_date` TIMESTAMP( 32 ) NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`visitor_day` SMALLINT( 2 ) NOT NULL ,
`visitor_month` SMALLINT( 2 ) NOT NULL ,
`visitor_year` SMALLINT( 4 ) NOT NULL ,
`visitor_refferer` VARCHAR( 255 ) NULL ,
`visitor_page` VARCHAR( 255 ) NULL
) TYPE = MYISAM ;
|
Quote:
<?php
$hostname_visitors = "localhost";
$database_visitors = "growa";
$username_visitors = "root";
$password_visitors = "password";
$visitors = mysql_connect($hostname_visitors, $username_visitors, $password_visitors) or trigger_error(mysql_error(),E_USER_ERROR);
function getBrowserType () {
if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
}
else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT']))
{
$HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
}
else if (!isset($HTTP_USER_AGENT))
{
$HTTP_USER_AGENT = '';
}
if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version))
{
$browser_version = $log_version[2];
$browser_agent = 'opera';
}
else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version))
{
$browser_version = $log_version[1];
$browser_agent = 'ie';
}
else if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version))
{
$browser_version = $log_version[1];
$browser_agent = 'omniweb';
}
else if (ereg('Netscape([0-9]{1})', $HTTP_USER_AGENT, $log_version))
{
$browser_version = $log_version[1];
$browser_agent = 'netscape';
}
else if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version))
{
$browser_version = $log_version[1];
$browser_agent = 'mozilla';
}
else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version))
{
$browser_version = $log_version[1];
$browser_agent = 'konqueror';
}
else
{
$browser_version = 0;
$browser_agent = 'other';
}
return $browser_agent;
}
function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
function paginate($start,$limit,$total,$filePath,$otherPara ms) {
global $lang;
$allPages = ceil($total/$limit);
$currentPage = floor($start/$limit) + 1;
$pagination = "";
if ($allPages>10) {
$maxPages = ($allPages>9) ? 9 : $allPages;
if ($allPages>9) {
if ($currentPage>=1&&$currentPage<=$allPages) {
$pagination .= ($currentPage>4) ? " ... " : " ";
$minPages = ($currentPage>4) ? $currentPage : 5;
$maxPages = ($currentPage<$allPages-4) ? $currentPage : $allPages - 4;
for($i=$minPages-4; $i<$maxPages+5; $i++) {
$pagination .= ($i == $currentPage) ? "<a href=\"#\"
class=\"current\">".$i."</a> " : "<a href=\"".$filePath."?
start=".(($i-1)*$limit).$otherParams."\">".$i."</a> ";
}
$pagination .= ($currentPage<$allPages-4) ? " ... " : " ";
} else {
$pagination .= " ... ";
}
}
} else {
for($i=1; $i<$allPages+1; $i++) {
$pagination .= ($i==$currentPage) ? "<a href=\"#\" class=\"current\">".$i."</a> "
: "<a href=\"".$filePath."?start=".(($i-1)*$limit).$otherParams."\">".$i."</a> ";
}
}
if ($currentPage>1) $pagination = "<a href=\"".$filePath."?
start=0".$otherParams."\">FIRST</a> <a href=\"".$filePath."?
start=".(($currentPage-2)*$limit).$otherParams."\"><</a> ".$pagination;
if ($currentPage<$allPages) $pagination .= "<a href=\"".$filePath."?
start=".($currentPage*$limit).$otherParams."\">> ;</a> <a href=\"".$filePath."?
start=".(($allPages-1)*$limit).$otherParams."\">LAST</a>";
echo '<div class="pages">' . $pagination . '</div>';
}
?>
|
Quote:
<?php
require_once('visitors_connections.php');//the file with connection code and functions
//get the required data
$visitor_ip = GetHostByName($_SERVER['REMOTE_ADDR']);
$visitor_browser = getBrowserType();
$visitor_hour = date("h");
$visitor_minute = date("i");
$visitor_day = date("d");
$visitor_month = date("m");
$visitor_year = date("Y");
$visitor_refferer = GetHostByName($_SERVER['HTTP_REFERER']);
$visitor_page = selfURL();
//write the required data to database
mysql_select_db($database_visitors, $visitors);
$sql = "INSERT INTO visitors_table (visitor_ip, visitor_browser, visitor_hour,
visitor_minute, visitor_day, visitor_month, visitor_year,
visitor_refferer, visitor_page) VALUES ('$visitor_ip', '$visitor_browser',
'$visitor_hour', '$visitor_minute', '$visitor_day', '$visitor_month',
'$visitor_year', '$visitor_refferer', '$visitor_page')";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);?>
|
Quote:
<?php
require_once('visitors_connections.php');//the file with connection code and functions
if ($_GET['start'] == "") $start = 0;
else $start = $_GET['start'];
$limit = 20;
$additionalQuery = "SQL_CALC_FOUND_ROWS ";
mysql_select_db($database_visitors, $visitors);
$query_visitors = "(SELECT ".$additionalQuery." * FROM visitors_table WHERE";
if ($_POST['day']!="") {
$query_visitors .= " visitor_day = '".$_POST['day']."'";
} else {
$query_visitors .= " visitor_day = ".date("d")."";
if ($_POST['month']!="") {
$query_visitors .= " AND visitor_month = '".$_POST['month']."'";
} else {
$query_visitors .= " AND visitor_month = ".date("m")."";
}
if ($_POST['year']!="") {
$query_visitors .= " AND visitor_year = '".$_POST['year']."'";
} else {
$query_visitors .= " AND visitor_year = ".date("Y")."";
}}
$query_visitors .= " LIMIT $start,$limit)";
$insert_visitors = mysql_query($query_visitors, $visitors) or die(mysql_error());
$row_visitors = mysql_fetch_assoc($insert_visitors);
$totalRows_visitors = mysql_num_rows($insert_visitors);
$nbItems = mysql_result(mysql_query("Select FOUND_ROWS() AS nbr"),0,"nbr");
if ($nbItems>($start+$limit)) $final = $start+$limit;
else $final = $nbItems;
echo '<link href="style.css" rel="stylesheet" type="text/css" />';
echo '<table style="width:100%; border:1px dashed #CCC" cellpadding="3">
<form id="form1" name="form1" method="post" action="display_visits.php">
<tr>
<td>day
<select name="day" id="day">
<option value="" selected="selected"></option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select></td>
<td>Month
<select name="month" id="month">
<option value="" selected="selected"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select></td>
<td>Year
<select name="year" id="year">
<option value="" selected="selected"></option>
<option value="2007">2007</option>
</select></td>
<td><input type="submit" name="Submit" value="Submit" /></td>
<td></td>
</tr>';
echo '<tr>
<td style="width:15%;border-bottom:1px solid #CCC">IP</td>
<td style="width:15%;border-bottom:1px solid #CCC">Browser</td>
<td style="width:15%;border-bottom:1px solid #CCC">Time</td>
<td style="width:30%;border-bottom:1px solid #CCC">Refferer</td>
<td style="width:25%;border-bottom:1px solid #CCC">Page</td>
</tr>';
do {
echo '<tr onmouseout="this.style.backgroundColor=\'\'"
onmouseover="this.style.backgroundColor=\'#EAFFEA\ '">
<td>'.$row_visitors['visitor_ip'].'</td>
<td>'.$row_visitors['visitor_browser'].'</td>
<td>'.$row_visitors['visitor_hour'].':'.$row_visitors['visitor_minute'].'</td>
<td>'.$row_visitors['visitor_refferer'].'</td>
<td>'.$row_visitors['visitor_page'].'</td>
</tr>';
} while ($row_visitors = mysql_fetch_assoc($insert_visitors));
paginate($start,$limit,$nbItems,"display_visits.ph p","");
?>
|
|
|
|
|
|
« Reply to Tracking System
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|