generate log file(or track user)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simran10101
Forum Newbie
Posts: 3
Joined: Sat Aug 07, 2010 3:10 am

generate log file(or track user)

Post by simran10101 »

I need to create logs of each user for eg when user enter into session(after login) I want to track its each activity.(where he click) . plz send your valuable suggestions to perform this task .
User avatar
phpcip28
Forum Newbie
Posts: 22
Joined: Sun Aug 29, 2010 1:38 pm
Location: NewYork
Contact:

Re: generate log file(or track user)

Post by phpcip28 »

If you do NOT use codeigniter this is not as easy , BUT easy enough.

So what you have to do is create a database table called visitors
it would have the following fields

ID - primary key, unique key of INTEGER type.
user_id - this should be the user_id that you are storing inside the $_SESSION.
page_visited - of type VARCHAR 250 chars
time_visited - of type DATETIME

And on your each page in the header somewhere do this

Code: Select all

if($_SESSION['user_id']){

    //Now the user is logged in, so just insert all his actions in the database table you've just created.

    mysql_query("INSERT INTO visitors (......................) VALUES (..................)");
}
Maybe also add an IP address field to that table and so forth.

Hope this makes sense.
Post Reply