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
Date:2009-05-20
Level:Beginner
Product:See complete product
Viewed:41094

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:

Code:
  1. <?php
  2. $src = isset($_GET['src']) ? $_GET['src'] : "-";
  3. $dst = isset($_GET['dst']) ? $_GET['dst'] : "-";
  4.  
  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
AJAX F1
HTML F1
CSS F1
Java F1
JavaScript F1
PHP F1
SQL F1
Developer F1

Family tutorials
PHP Array
PHP8 on Windows10
Not a supported stylesheet mime type

Resources
PHP Utils

Total time: 0.0058