Page 1 of 1
how to track user activity
Posted: Mon May 12, 2003 12:53 pm
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
Posted: Mon May 12, 2003 1:06 pm
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
Further clarification of my question
Posted: Mon May 12, 2003 1:12 pm
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
Posted: Mon May 12, 2003 1:55 pm
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
how to track user activity (continued)
Posted: Tue May 13, 2003 7:49 am
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
Posted: Tue May 13, 2003 8:38 am
by volka
redirected to
http://php.net/session and zend's session tutorial via pm.