View Full Version : Auto Insert
Neebski
09-08-2007, 10:14 PM
Hey there, I am trying to put together a log type database of where each user goes and what pages they view. How can I automatically add an entry into my log db each time the page loads? (As of right now it only logs things when a button is pushed)
Thanks!
- Kevin Neberman
<?php
$f = fopen('user_activity.log');
fwrite($f, sprintf('%s: %s viewed %s.', date('r'), $username, $_SERVER['REQUEST_URI']));
fclose($f);
?>
tech_support
09-09-2007, 03:18 AM
It'd be much better to use MySQL if you have a lot of users. Some logs go 10GB+ on active websites.
Oh yes, you actually said "database." Missed that, sorry.
<?php
// connect, blah, blah
pg_query(sprintf('insert into log (time, user, page) values (\'%s\', \'%s\', \'%s\')',
date('r'),
$username,
$_SERVER['REQUEST_URI']
));
?>
tech_support
09-09-2007, 03:38 AM
Hmm... a database could also be a text file.
At a stretch. Well, either way, the code's there.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.