Php-mysql Course

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.

- This script is Free, without assistance, you can use it, modify, and publish it freely.

• To Download the script, click: Website Traffic and Pages Access data

Records and displays these statistics for your website:

Requirements

- PHP 5.4+ with PDO extension enabled.
- Web Browser with HTML5 support, and JavaScript enabled.

Traffic data can be saved in text files on the server, or into a MySQL database (using PDO). If your website has more than 5000 pages, it is indicated to use MySQL database.
- For installation, see the instructions in "Readme.html" file, in the archive with the script.
The HTML code is valid XHTML. The script cames with two design styles: traffic data displayed horizontally (defined in "siteaccess_h.css"), and vertically (defined in "siteaccess_v.css"), like in these images.

- Horizontally (click the image)
Website Traffic and Pages Access data, horizontally

- Vertically
Website Traffic, Pages Access, vertically

Advanced Settings

- To use the script in other language, just translate the texts in "lang.php" file ("siteaccess" directory).
- By default, the script shows the last 8, and top 8 accessed pages. To change this number, modify the values of $nrlastacc and $nrtopacc variables, in "siteaccess.php".
$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.
- The HTML code with site traffic data is defined in the getTraff() method, in "class.MiniTrafic.php" file.

These methods can be used in PHP file to get the website access data separatelly (after including "siteaccess.php" file):
- The script registers traffic data after the user stays 5 seconds on page. To modify this number of seconds, change the value of nrsecacc variable, in "siteaccess.js".
var nrsecacc = 5;

The script was succesfully tested on localhost (with XAMPP), and on this website, with Mozilla Firefox, Internet Explorer, Google Chrome, and Opera.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which HTML element can be used to embed a SWF flash content?
<object> <div> <script>
<object type="application/x-shockwave-flash" data="file.swf" width="500" height="250">
 <param name="src" value="file.swf" />
 Your browser not support SWF.
</object>
Which CSS pseudo-class adds a style to an input form field that has keyboard input focus?
:active :focus :hover
input:focus {
  background-color: #88fe88;
}
Click on the instruction which converts a JSON string into a JavaScript object.
JSON.stringify(javascript_object) object.toString() JSON.parse(json_string)
var jsnstr = '{"url": "http://coursesweb.net/", "title": "Web Development Courses"}';
var obj = JSON.parse(jsnstr);
alert(obj.url);
Indicate the PHP function which can be used to create or write a file on server.
fopen() file_put_contents() file_get_contents()
if (file_put_contents("file.txt", "content")) echo "The file was created";
else echo "The file can not be created";
Website Mini-Traffic and Pages Access data

Last accessed pages

  1. JavaScript Course - Free lessons (31647)
  2. Volume and Surface Area Calculator for 3D objects (11276)
  3. Using v-model in form input fields (1051)
  4. jQuery UI draggable - Drag elements (11445)
  5. Display data from PHP Array, or MySQL in HTML table (26980)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (310)
  2. The Mastery of Love (48)
  3. CSS cursor property - Custom Cursors (36)
  4. Read Excel file data in PHP - PhpExcelReader (35)
  5. PHP-MySQL free course, online tutorials PHP MySQL code (31)