how to track user activity

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jiehuang001
Forum Commoner
Posts: 39
Joined: Mon May 12, 2003 12:53 pm

how to track user activity

Post by jiehuang001 »

Hi, I am developing a course website to put some study webpages online. I need to track which user has visited what pages so that I can know the students' study progress. Please refer me to an sample code.

Many thanks.

Jie Huang
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

u can keep track of the students ip address, or u can always use a cookie that saves a certain variable for each acessed page
jiehuang001
Forum Commoner
Posts: 39
Joined: Mon May 12, 2003 12:53 pm

Further clarification of my question

Post by jiehuang001 »

Hi, maybe I didn't state my question clearly. For example, I have 10 pages which are named page1, page2, page3... page 10. When someone visited one of those pages, I want the following information to be recorded into a table:
UserName, Time, PageName

Of course, the user needs to login first so that I can log his UserName.

Jie Huang
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe something like

Code: Select all

// mysql-connection has been established somewhere else and stored in $GLOABLS['dbConn']
function visited($who, $where)
{
	$query = 'INSERT INTO tblName values(`who`,`location`,`when`) VALUES (' . mysql_escape_string($who) . ',' . mysql_escape_string($where) . ',  Now())';
	mysql_query($query, $GLOABLS['dbConn']);
}

Code: Select all

...
visited($_SESSION['uname'], 'index.php');
...
maybe you want to use http://www.php.net/manual/en/configurat ... epend-file
jiehuang001
Forum Commoner
Posts: 39
Joined: Mon May 12, 2003 12:53 pm

how to track user activity (continued)

Post by jiehuang001 »

Hi, Volka:

Great, the code works! Here is a further question. If the user begins from login.html then to page1.php, page2.php... page10.php. How can I get the $_SESSION['username'] in the page2.php... page10.php?

Also, if there are multiple users are visiting the pages. how to identify which username is who?

I am a PHP beginner, please help.

Many thanks.

Jie Huang
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

redirected to http://php.net/session and zend's session tutorial via pm.
Post Reply