Seeing when user accessed site

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
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Seeing when user accessed site

Post 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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Re: Seeing when user accessed site

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post 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
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post by dru_nasty »

Thanks, I'll play around with this.
I'll post with what I come up with.
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post 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.
Post Reply