Ajax click tracking - The server side script

Home - Tutorials - AJAX basic tutorials

This tutorial demonstrates a simple and easy way how to track your visitors clicks using Ajax and PHP.

Tutorial info:

Name:Ajax click tracking
Total steps:2
Category:AJAX basic tutorials
Product:See complete product

Bookmark Ajax click tracking

AddThis Social Bookmark Button

Step 2 - The server side script

Ajax click tracking

As you could see the onClick event triggers the doWork() javascript function on the clickDemo.html file. The doWork() function calls (visits) the server side script clickTrack.php and pass the source and target information as URL parameters. It means we need to process the $_GET array in the PHP code.

If we get the variables then we can simply write them into a text file and that's it. The code is small and simple:

  1. <?php
  2. $src = isset($_GET['src']) ? $_GET['src'] : "-";
  3. $dst = isset($_GET['dst']) ? $_GET['dst'] : "-";
  5. $f = fopen('clickReport.txt',"a+");
  6. fwrite ($f, date('Y-m-d H:i'));
  7. fwrite ($f, " : " + $src + " : " + $dst + "\r\n");
  8. fclose($f);
  9. ?>

Now we are ready. There are of course lot of improvement possibilities but it is up to you.


Previous Step of Ajax click tracking

Tags: ajax click tracking, click recording, ajax, click, tracking, recording

Ajax click tracking - Table of contents
Step 1 - Ajax click tracking
Step 2 - The server side script

F1 Site Family
Java F1
JavaScript F1

Family tutorials
PHP Array
PHP Redirect
PHP Session
MySQL Create User
Mysqldump Example
MySQL Concat
JavaScript String
JavaScript Timeout
JavaScript Tooltip

Total time: 0.1012