Tracking the number of users that visit the pages of Web site is a common type of application found in many sites.
This is a PHP /Ajax script to register and display simple website traffic statistics, and Pages Access data.
Sometimes it is hard to distinguish site accesses done by real human users from robot accesses.
This script implements an approach that uses AJAX requests to validate accesses done by real human users using real browsers, staying the pages for at least 5 seconds. This period is a configurable parameter.
The website access data is not registered again if the page is refreshed.
This script not records the accesses performed by well known crawler robots (Googlebot, alexa, Gigabot, MSN, Yahoo, ..., and others, over 170 bots), and it can be included in both .php and .html files (but the server must run PHP).
Can be easily used in other language, just translating texts in a single file.
$nrlastacc = 8; $nrtopacc = 8;- Default Timezone for date and time is set to "Europe/London", in "siteaccess.php".
@date_default_timezone_set('Europe/London');- If the script is not copied in the root directory of your website, put an absolute /full path (with "http://", or "https://") to "siteaccess.php" in "siteaccess.js" (line 13).
ob_ajax.open('POST', 'http://domain/path/siteaccess.php', true);- If you want to not display the list with last accessed pages, delete (or comment) this line of code in "siteaccess.php".
$siteaccess .= '<div id="pgalast"><h4>Last accessed pages</h4>'. $objSA->getLastPages($nrlastacc) . '</div>';- To not display the list with most accessed pages in current month, delete (or comment) this line of code in "siteaccess.php".
$siteaccess .= '<div id="pgatop_m"><h4>Top pages this month</h4>'. $objSA->topMonth($nrtopacc) . '</div>';- If you want to not display the list with top accessed pages, delete (or comment) this line of code in "siteaccess.php".
$siteaccess .= '<div id="pgatop"><h4>Top accessed pages</h4>'. $objSA->getTopPages($nrtopacc) . '</div>';- To not display websites traffic data, delete (or comment) this line of code in "siteaccess.php".
$siteaccess .= $objMT->getTraff($objSA->currentpage);- The HTML <OL> list for Last and Top accessed pages is defined in setHtmlLi() method, in "class.PagesAccess.php" file.
var nrsecacc = 5;
<table><tr> <th>Title 1</th> <th>Title 2</th> </tr></table>
.some_class { line-height: 150%; }
document.getElementById("id_button").onclick = function(){ window.open("http://coursesweb.net/"); }
$ar_dir = scandir("dir_name"); var_export($ar_dir);