Can user_lastvisit and user_session_time be reset to 0 ?

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
harknell
Registered User
Posts: 39
Joined: Mon Mar 14, 2005 12:08 am
Contact:

Can user_lastvisit and user_session_time be reset to 0 ?

Post by harknell » Mon Nov 13, 2006 1:38 am

can either user_lastvisit or user_session_time in the users table ever be reset to 0 by an admin action if they have ever had a value?

A mod I've written needs to find a way of determining between a de-activated or unactivated user. (so the difference between a user who registered and never activated versus a user who activated and logged in and such, but has now become user_active=0 by the admin setting them as inactive)

So, I want to use the idea that if the field user_lastvisit has a value, then obviously the user has actually logged in and used the site, the same with user_session_time. But I want to make sure there isn't a way for these values to get reset to 0 through an admin action. I can't see how they would be reset, but I'm not taking any chances.

Anyone have any input on if this is the correct way to do this?
Webmaster of the webcomic http://www.onezumi.com
The Art, The Comic, The Insanity

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun » Mon Nov 13, 2006 6:26 am

I don't believe that user_lastvisit ever gets reset to zero. In the entire set of files for phpbb2 version 2.0.21, user_lastvisit is only touched in includes/page_header.php (you last visited on... message), includes/sessions.php (gets updated here), index.php (used for a limit as to how far back to go to mark "Unread" topics), search.php (the "find posts since last visit" is obvious, also used to mark unread topics) and viewforum and viewtopic (also topic tracking).

From what I can tell, sessions.php is the only place in the code where user_lastvisit is updated.

If you work on a linux box and use vi as your editor the following command is nice:

Code: Select all

vi `grep -ilr user_lastvisit *`
The backquotes capture the results of the grep command and pass them to vi, allowing you to quickly edit / review any file in the recursive (the -r part of the option) phpbb code tree. 8)
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

ycl6
Translator
Posts: 5696
Joined: Sat Feb 15, 2003 10:35 am
Location: Taiwan
Contact:

Post by ycl6 » Mon Nov 13, 2006 12:12 pm

I agree with Dave, after looking at files that contain the necessary codes, the only file that changes both user_lastvisit and user_session_time is sessions.php

For user_lastvisit

Code: Select all

		if (!$admin)
		{
			$sql = "UPDATE " . USERS_TABLE . " 
				SET user_session_time = $current_time, user_session_page = $page_id, user_lastvisit = $last_visit
				WHERE user_id = $user_id";
			if ( !$db->sql_query($sql) )
			{
				message_die(CRITICAL_ERROR, 'Error updating last visit time', '', __LINE__, __FILE__, $sql);
			}
		}
For user_session_time

Code: Select all

					if ( $userdata['user_id'] != ANONYMOUS )
					{
						$sql = "UPDATE " . USERS_TABLE . " 
							SET user_session_time = $current_time, user_session_page = $thispage_id
							WHERE user_id = " . $userdata['user_id'];
						if ( !$db->sql_query($sql) )
						{
							message_die(CRITICAL_ERROR, 'Error updating sessions table', '', __LINE__, __FILE__, $sql);
						}
					}
~Mac

Wo1f
Registered User
Posts: 2039
Joined: Fri Jan 28, 2005 3:20 am

Re: Can user_lastvisit and user_session_time be reset to 0 ?

Post by Wo1f » Mon Nov 13, 2006 5:03 pm

Hi harknell,
harknell wrote: can either user_lastvisit or user_session_time in the users table ever be reset to 0 by an admin action if they have ever had a value?

A mod I've written needs to find a way of determining between a de-activated or unactivated user. (so the difference between a user who registered and never activated versus a user who activated and logged in and such, but has now become user_active=0 by the admin setting them as inactive)

So, I want to use the idea that if the field user_lastvisit has a value, then obviously the user has actually logged in and used the site, the same with user_session_time. But I want to make sure there isn't a way for these values to get reset to 0 through an admin action. I can't see how they would be reset, but I'm not taking any chances.

Anyone have any input on if this is the correct way to do this?


I already have working code that does this (User Shield v1.4.2) which is a major upgrade to v1.2.1 and still being tested right now (has not been submitted for validation yet). Basically it breaks down the registration process and among other things isolates "Reverted" members. These would be members that have asked for an email change through their profile form or have been deactivated by the admin. for reason x.

Code: Select all

'AND user_active != 1 AND user_lastvisit > 0'
The 'user_last_visit' field as confirmed by drathbun and ycl6 does not get reset to zero. Keep in mind that having a value > 0 does not imply member activity on the board but does confirm that the account was activated and the member logged in at least once and may or may not have created board activities. But there's your difference versus 'never activated' registered members (those who have submitted a registration form) but have not activated the account or the admin. has not.

Hope this is helpful,


Regards,
Wolf

Post Reply

Return to “[2.0.x] MOD Writers Discussion”