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
how to track user activity
Moderator: General Moderators
-
jiehuang001
- Forum Commoner
- Posts: 39
- Joined: Mon May 12, 2003 12:53 pm
-
jiehuang001
- Forum Commoner
- Posts: 39
- Joined: Mon May 12, 2003 12:53 pm
Further clarification of my question
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
UserName, Time, PageName
Of course, the user needs to login first so that I can log his UserName.
Jie Huang
maybe something likemaybe you want to use http://www.php.net/manual/en/configurat ... epend-file
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');
...-
jiehuang001
- Forum Commoner
- Posts: 39
- Joined: Mon May 12, 2003 12:53 pm
how to track user activity (continued)
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
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
redirected to http://php.net/session and zend's session tutorial via pm.