wap Bluetooth 3g contact Affordable advertising with wuzap
navigation

Tracking WAP Users

Using PHP & WAP part II
By Andrew Spiers

When I setup my WAP site (), I wanted to be able to see what pages the visitors were visiting, where they came from and to also be able to see what phones that they were using, so I setup my own user tracking system using PHP & MySQL.

First thing was to create the table, using the following definitions :

Column Name Type Extra
track_id int auto_increment
track_timestamp timestamp
filename char(50)
user_agent char(50)
referer char(75)

Once that was done, it was just a matter of creating the code to insert into the table :

/* Configuration Section */
$hostname = "Localhost:3306";
$userid = "myuser";
$passwd = "mypassword";
/* End Configuration Section */

// Connect to MySql server
$db=mysql_connect($hostname,$userid,$passwd) or die (mysql_error());
mysql_select_db("mydatabase",$db) or die (mysql_error());

$hua = getenv("HTTP_USER_AGENT");
$hr = getenv("HTTP_REFERER");
$pi = getenv("SCRIPT_NAME");
$app = "Wap_Rovers";

Ø $result = mysql_query ("INSERT INTO tracking (application, file_name,
user_agent, referer) VALUES ('$app','$pi','$hua','$hr')") or
die(mysql_error());

As you can see, a very simple script, the first few lines enable me to change the user or password. The next section connects to mysql and selects 'mydatabase'. Then comes the important part, this gets the values to be inserted into the tracking table. These are :

$hua = getenv("HTTP_USER_AGENT");
Name of phone.

$hr = getenv("HTTP_REFERER");
Address of the site where the user has just come from.

$pi = getenv("SCRIPT_NAME");
Name of the script running

$app = "Wap_Rovers";
This enables me to use the tracking database for different applications.

The last line inserts the values into the table, track_timestamp is automatically updated with the current date and time.

To use this script, it is as simple as changing the userid / password / database for your site and then adding it to the top of any of your PHP/WML pages. You can then run some simple queries against the database to see what the most popular phone is for people visiting your site or which site is giving you the most referrals.

There is scope to improve the script as the timestamp is not in the most readable format and it doesn't assign a session id to a user but I will leave this for you to do !!!

Wuzap Newsletter

Links