I need help to track the user action

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

I need help to track the user action

Post by tamilmani »

Hi Dudes,

I have to track the users action like as select , update , deletion , login and logut .... etc

I have to trach each the action and store into database .

Please any one help to me .

Regards

Tamilani Mohan
8)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I need help to track the user action

Post by AbraCadaver »

You can write a wrapper function for your queries that inserts the user action in a histories table.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: I need help to track the user action

Post by greyhoundcode »

I often use the Kohana framework which already has logging facilities:

Code: Select all

Kohana::log('info', "User $userID ($username) logged in at " . date());
Of course, this writes to a text-based log file rather than a database, but the principal holds good. Nor would you need a framework's implementation, it would be very easy to make your own.

Either that, or what AbraCadaver said :wink:
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

Re: I need help to track the user action

Post by tamilmani »

please give me some sample code ......
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I need help to track the user action

Post by AbraCadaver »

tamilmani wrote:please give me some sample code ......

Code: Select all

function my_query($query) {
    $result = mysql_query($query);
    $action = mysql_real_escape_string($query);
    $userid = mysql_real_escape_string($_SESSION['userid']);
    mysql_query("INSERT INTO history (`action`, `userid`, `updated`) VALUES ('$action', '$userid', NOW())");
 
    return $result;
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply