Page 1 of 1

Seeing when user accessed site

Posted: Thu Dec 15, 2005 7:13 am
by dru_nasty
I have a site that stores login info of a user. (e.g. username, password, name, etc..)

Is there a script that would tell me when a certain user accessed certain pages of the site?

Any help in pointing me in the right direction is appreciated.

Thanks :D

Re: Seeing when user accessed site

Posted: Thu Dec 15, 2005 7:19 am
by BDKR
dru_nasty wrote: Is there a script that would tell me when a certain user accessed certain pages of the site?
Do you write code?

Check some of the scripting repository sites. Hotscripts is one possibility.

Posted: Thu Dec 15, 2005 7:20 am
by Chris Corbyn
This is fairly easy.

1. User logs in
2. Every time a user clicks a link you insert into or update a table in the database with the current page, and a timestamp.


You can then also do things like check how many users are on your site (users active in the last 5 mins), check which pages are visited most frequently and check access times.... pretty useful thing to do.

Posted: Thu Dec 15, 2005 10:37 am
by dru_nasty
I know the basics of php/mysql, I'm still learning though, so yes I do a little scripting, but it's mostly retrieving/ submitting date to and from the db.

Can anyone put together a bit of a sample? Or even maybe explain in plain english and I can give it a crack scripting it.

Thanks

Posted: Thu Dec 15, 2005 10:53 am
by foobar
dru_nasty wrote:Can anyone put together a bit of a sample? Or even maybe explain in plain english and I can give it a crack scripting it.
d11wtq wrote: 2. Every time a user clicks a link you insert into or update a table in the database with the current page, and a timestamp.
On every page, you have something similar to the following:

The "main" page:

Code: Select all

<?php

/* Include the "counter" script */
include('user_access.php');

/* ... the rest of the page ... */

?>
user_access.php:

Code: Select all

<?php

/* Assuming user data was saved in the following fashion... */
$userid = $_SESSION['userid']; //<-- retrieve user ID from session variables

/* Query database & add to counter */
mysql_query("UPDATE user_table SET last_access_time = ".time()." WHERE user_id = ".$userid);

?>
Quick 'n' dirty.

Posted: Thu Dec 15, 2005 12:58 pm
by dru_nasty
Thanks, I'll play around with this.
I'll post with what I come up with.

Posted: Sun Dec 18, 2005 6:22 pm
by dru_nasty

Code: Select all

$date = date ( 'g:i A l, F j Y.' );
$query_user = "UPDATE registered_mem SET last_access_time = '$date' WHERE username = '$username'"; 
$result = mysql_query($query_user, $db_conn) or die(mysql_error());
Just used the date(); function instead of time();.
Works great!
Thanks for the help everyone.