Forum Moderators: coopster

Message Too Old, No Replies

Visitor's Tracking

         

itwebxpert

11:29 am on Jan 20, 2005 (gmt 0)

10+ Year Member



Hi All,

I am currently trying to develop a small php-written application which allow me to track every single visitor coming to my website.

I would like to track each visitor by IP address, Port number, Session, the pages they visit, and want to identify which visitor is the returned one.

I do need some help from all of you. Can anyone give an idea of how to do that, or give me links to webpages where I can retrieve info about that.

Thank you in advance.

grandpa

12:19 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need an understanding of sessions.

You might need an understanding of classes. I found a Class object (phpsniff) that returns most of the info you are looking for.

The way I accomplished the same task was to create a series of include files. The first sets up the standard header for each page. Next comes the include file that checks for known spiders. I don't start sessions for those visitors. But I do track them. Next is the include that starts my sessions, when needed, and the final include logs everything to the tables in the database. I also end each page with a final include that logs the end time of the script. This is useful for me, just to know the pages are being completely sent.

That's the basics without a lot of detail. From scratch I probably spent a couple of weeks developing and deploying this to most of the pages on my site. The only part that needs to be maintained is the include file which contains my bot list.

What makes this nice is using the include files. Any page I want to include in my tracking now takes a standard piece of code at the beginning.

<?php
//error_reporting(E_ALL);
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
$filename = 'page.php';
$stdate = date('Ymd');
$sttime = date('His');
//global variables defined here
include ("header.inc"); // send page header
include ("connect.inc"); // database connection
include ("phpsniff.inc"); // sniffer class
$mysniff = new phpSniff();
include ("checkbot_A.inc"); // bot checker
if (!$my_return) { // no robot detected, start the session
include ("sessreg.inc"); // session control
}
include ("tracking.inc"); // log the data
?>

That gets the information I want into my database. Now I want to be able to use it. For that I built a screen that will display my records with pagination, and I can sort and view the data in a number of different ways. One of these days I might start making graphs....

itwebxpert

12:41 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Thank you very much for some ideas.

I know what session is. I have done classes in C++ and some in Java, but not php classes yet. By the way, your codes look very simple. Can you advise me the quickest way to find that information?

Thank you in advance again.

Cheers

grandpa

1:39 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might try a search for the phpsniffer on your favorite search engine. I think I found it at phpclasses.org. Information about known good/bad spiders and bots is lurking around WebmasterWorld. Everything else, from using includes to what I put in them I gleaned from this forum.

itwebxpert

1:54 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Thanks lots.

However, I got a php scripts which do not use classes, but can track visitor too. Here it is:

<?
include ('incFiles/MySQLConnect.php');
include ('incFiles/MySQLQuery.php');
include ('incFiles/StartHTML.php');
include ('incFiles/EndHTML.php');
include ('incFiles/Insert.php');

etc.

But it only track visitor's IP, Port, session, php_self, etc. I want it to be more powerful which can track which user is returning one, etc. You think do we require classes to do so?

Cheers

grandpa

2:14 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are already getting all the information then you don't need to use a class object. I offered that as one possible solution.

It sounds more like you need to work out the reporting end. Using the same info that you are getting, I can spot return visitors on a given ip address. I can use the ip address or the session id to view my visitor habits. While less reliable, the ip address is my primary group for the initial display of site traffic. Less reliable, because any one ip address could be used by many visitors.

It's just come to me that maybe what you want, for tracking returning visitors, is to set a cookie for each visitor. It's probably the only reliable way to know that someone has returned.

itwebxpert

2:41 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Thank you again.

I think we cannot use IP address to track a returning visitor as IP address is changed (dynamic IP address) every time the user connect to the Internet using dial up Internet connection.

Setting cookies involve sometimes using form results written to a user's file in his/her hard disk. But in this case, the visitor does not fill in any form or buy any thing. What parametres should be used then for cookies? I think they must be unique for each user?

I appreciate your help.

Cheers

itwebxpert

7:55 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Hi All,

I tested successfully the codes below to identify a returning user/visitor:

//Test if the session is started;
//otherwise, start it:
if(!session_id()){
session_start();
echo 'Session is just started!<br><br>';
}

//If the cookie has been set previously,
//Do not set it again; otherwise, write a
//new cookie into visitor file on hard disk:
if (isset($_COOKIE["session_id"]))
echo "Welcome back, " . $_COOKIE["session_id"] . "!<br>";
else{
setcookie("session_id", $session_id, time()+36000);
echo "You are a new visitor<br>";
}

IT IS VERY SIMPLE!

Cheers