December 29, 2011

how to know how many pages a particular user visited in a particular session

Question by Anup Kumar

i am working on a e-commerce website, i want to monitor how many pages a users visited in a particular session. there are only registered users of the site.
can any one tell me how to record the URL of the user of a particular session,
i am using php and mysql

Answer by Starx

There are more than one way to do this. Here is one quick walkthrough:

  1. Create a table with two fields (‘session_id’, ‘url’);

  2. Whenever the site loads, read the sessionid using session_id(), and use this value to store the url of the page in a table for every pages the people visit.

  3. Once a page loads, read the URL, through $_SERVER['REQUEST_URI']; and then use it the value of session_id() and store the records.

After you implement this simple technique. you can see how many people see the pages, using a simple query

SELECT count(*) FROM <YOURSESSIONTABLE> GROUP BY `<session_id_field>`

P.S. This is one of the basic example, and should be changed to fit your requirements

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!