This option will reset the home page of this site. Restoring any closed widgets or categories.

Reset

Simple Ajax with PHP click tracker

This tutorial shows how to track your vistors click using simple php and Ajax To implement the click tracking tool we need to create 2 files:
Demo.html: This file contains the html with the links and the Ajax code.
clickTracker.php: This files will be called by Ajax and records the click event.
DEMO.HTML will look like this

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Ajax click tracking example</title>
<script language=”javascript” type=”text/javascript”>
function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject(”Microsoft.XMLHTTP”);
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert(”Your browser does not support AJAX.”);
return null;
}
}
// Change the value of the outputText field
function setOutput(){
return true;
}
// Implement business logic
function doTrack(element){
httpObject = getHTTPObject();
if (httpObject != null) {
dst = element.href;
src = document.location.href;
httpObject.open(”GET”, “clickTracker.php?src=”+src+”&dst=”+dst, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput;
}
}
var httpObject = null;
var src = null;
var dst = null;
</script>
</head>
<body>
<a href=”http://www.mistonline.in/wp” onclick=”doTrack(this);” > Test Click </a>
</body>
</html>
Now our clickTracker.php file

We will write data dynamically using AJAX to a simple text file, If you are not sure how to read/write data using
a text file in php then
Code:
<?php
$src = isset($_GET['src']) ? $_GET['src'] : “-”;
$dst = isset($_GET['dst']) ? $_GET['dst'] : “-”;
$f = fopen(’Trackdata.txt’,”a+”);
fwrite ($f, date(’Y-m-d H:i’));
fwrite ($f, ” : ” + $src + ” : ” + $dst + “\r\n”);
fclose($f);
?>
Thats it finished.Now you can track your website clicks, Thanks ajaxf1
VN:F [1.5.7_846]
Rating: 9.2/10 (9 votes cast)
VN:F [1.5.7_846]
Rating: +3 (from 3 votes)

Related posts:

  1. Ajax Page With PHP
  2. Disabling right click menu using javascript Enhanced Version
  3. Get textbox value from dropdown using ajax and php
  4. Automatic Ajax Loading Images With Prototype
  5. Context Right Click Menu Using Javascript
  6. Get youtube video screenshot using simple php and javascript
  7. Simple Pagination Using PHP Script

Leave a Reply

Comments (required)

Spam Protected