Last visit info is NOT right update

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Car2013
Registered User
Posts: 87
Joined: Fri Nov 22, 2013 5:18 am

Last visit info is NOT right update

Post by Car2013 » Wed Feb 06, 2019 3:19 pm

Hello, guys.
I got a problem that I cant solve.

As we know, the info of user's last visit appears on merberlist_view and merberlist_body.
For me, on 'merberlist_view', it works fine... with the right last visit time of the users.
However, on 'merberlist_body' it shows other time, usually a date like moths before (!?). I just dont get it... specially because on both is being used the code {VISITED}. More specifically:

merberlist_view

Code: Select all

<h3>{L_USER_FORUM}</h3>
		<dl class="details">
			<dt>{L_JOINED}:</dt> <dd>{JOINED}</dd>
			<dt>{L_VISITED}:</dt> <dd>{VISITED}</dd>
merberlist_body

Code: Select all

<td>{memberrow.JOINED}</td>
		<!-- IF S_VIEWONLINE --><td>{memberrow.VISITED}&nbsp;</td><!-- ENDIF -->


Id appreciate any help with.
Thanks

User avatar
david63
Registered User
Posts: 16162
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Last visit info is NOT right update

Post by david63 » Wed Feb 06, 2019 3:32 pm

Those two variables {VISITED} and {memberrow.VISITED} are not the same.

It all depends on where the last visit is picked up from as there are two of them. There is one in the user table which, from memory, is only updated when a user's session ends and there is another one in the sessions table which is current. This has been an issue with phpBB for a long time.

If you want to get the most accurate then you will need to create a function to grab the data from both the sessions table and the user table and do a compare of the two (horrible messy bit of code!)
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Car2013
Registered User
Posts: 87
Joined: Fri Nov 22, 2013 5:18 am

Re: Last visit info is NOT right update

Post by Car2013 » Wed Feb 06, 2019 4:11 pm

I understand.
Actually I imagined that the only difference of the code {memberrow.VISITED} was that the info is specifically of the user I see.

Anyway. As I said, the info from {VISITED} from merberlist_view.html is the RIGHT one.
So, can I, in some way, 'emulate' that same info here to the merberlist_body.html ?

Could you help me with?

Thanks

User avatar
david63
Registered User
Posts: 16162
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Last visit info is NOT right update

Post by david63 » Wed Feb 06, 2019 4:14 pm

Car2013 wrote:
Wed Feb 06, 2019 4:11 pm
So, can I, in some way, 'emulate' that same info here to the merberlist_body.html ?
Not without re-writing core code - which is not something that I would want to do.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
warmweer
Registered User
Posts: 2116
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: Last visit info is NOT right update

Post by warmweer » Wed Feb 06, 2019 4:31 pm

The "Who Was Here" extension (not validated) has code which look in the sessions_table (and thus can also grab autologin users).
I used code from there to get the last visited datetime (dynamically correct) and it worked on 3.2.1 and on 3.2.3 (haven't checked it on later versions but I suspect it should still work).
My board's not broken, it just went peculiar

Car2013
Registered User
Posts: 87
Joined: Fri Nov 22, 2013 5:18 am

Re: Last visit info is NOT right update

Post by Car2013 » Wed Feb 06, 2019 6:07 pm

warmweer wrote:
Wed Feb 06, 2019 4:31 pm
The "Who Was Here" extension (not validated) has code which look in the sessions_table (and thus can also grab autologin users).
I used code from there to get the last visited datetime (dynamically correct) and it worked on 3.2.1 and on 3.2.3 (haven't checked it on later versions but I suspect it should still work).
Cool. Could you explain to me what did u do then exactly?
Thanks

User avatar
warmweer
Registered User
Posts: 2116
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: Last visit info is NOT right update

Post by warmweer » Wed Feb 06, 2019 6:40 pm

Car2013 wrote:
Wed Feb 06, 2019 6:07 pm
Cool. Could you explain to me what did u do then exactly?
Thanks
Not offhand (in code) (it was a 3.0 mod which I had expanded and tried to transform to an extension somewhere beginning 2017 but failed miserably.)
But download the extension to have a look at it. There's a php-file in there which looks at the session table and compares the values to those in a sort of copy of the sessions table (empied at the end of a calendar day). If the user is not yet in that copy, he is added. If he is in that table, the timestamp is overwritten by the new one. All I did extra was add more fields to the copytable and added the extra data.
AFAIR the original code was written by nickvergessen for a 3.0 mod.

IIRC there was more or less similar code in the 24h stats extension (which IIRC was validated).
My board's not broken, it just went peculiar

User avatar
david63
Registered User
Posts: 16162
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Last visit info is NOT right update

Post by david63 » Wed Feb 06, 2019 6:43 pm

If it is any help this is a function that I use - there may be better ways of doing it

Code: Select all

/**
	 * Get the user's last visit
	 * This is more accurate than user_lastvisit in the user table
	 *
	 * @param $user_id
	 * @return int|mixed|string $last_visit
	 * @access protected
	 */
	protected function get_last_visit($user_id)
	{
		$last_visit 	= '';
		$session_times	= array();

		$sql = 'SELECT session_user_id, MAX(session_time) AS session_time
			FROM ' . SESSIONS_TABLE . '
			WHERE session_time >= ' . (time() - $this->config['session_length']) . '
				AND ' . $this->db->sql_in_set('session_user_id', $user_id) . '
			GROUP BY session_user_id';

		$result = $this->db->sql_query($sql);

		while ($row = $this->db->sql_fetchrow($result))
		{
			$session_times[$row['session_user_id']] = $row['session_time'];
		}

		$this->db->sql_freeresult($result);

		$sql = 'SELECT user_lastvisit
			FROM ' . USERS_TABLE . '
			WHERE ' . $this->db->sql_in_set('user_id', $user_id);

		$result = $this->db->sql_query($sql);

		while ($row = $this->db->sql_fetchrow($result))
		{
			$session_time	= (!empty($session_times[$user_id])) ? $session_times[$user_id] : 0;
			if ($row['user_lastvisit'] == 0)
			{
				$last_visit = $this->language->lang('NO_VISIT');
			}
			else
			{
				$last_visit = (!empty($session_time)) ? $session_time : $row['user_lastvisit'];
				$last_visit = $this->user->format_date($last_visit);
			}
		}

		$this->db->sql_freeresult($result);

		return $last_visit;
	}
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Car2013
Registered User
Posts: 87
Joined: Fri Nov 22, 2013 5:18 am

Re: Last visit info is NOT right update

Post by Car2013 » Thu Feb 07, 2019 12:56 pm

david63 wrote:
Wed Feb 06, 2019 6:43 pm
If it is any help this is a function that I use - there may be better ways of doing it

Code: Select all

/**
	 * Get the user's last visit
	 * This is more accurate than user_lastvisit in the user table
	 *
	 * @param $user_id
	 * @return int|mixed|string $last_visit
	 * @access protected
	 */
	protected function get_last_visit($user_id)
	{
		$last_visit 	= '';
		$session_times	= array();

		$sql = 'SELECT session_user_id, MAX(session_time) AS session_time
			FROM ' . SESSIONS_TABLE . '
			WHERE session_time >= ' . (time() - $this->config['session_length']) . '
				AND ' . $this->db->sql_in_set('session_user_id', $user_id) . '
			GROUP BY session_user_id';

		$result = $this->db->sql_query($sql);

		while ($row = $this->db->sql_fetchrow($result))
		{
			$session_times[$row['session_user_id']] = $row['session_time'];
		}

		$this->db->sql_freeresult($result);

		$sql = 'SELECT user_lastvisit
			FROM ' . USERS_TABLE . '
			WHERE ' . $this->db->sql_in_set('user_id', $user_id);

		$result = $this->db->sql_query($sql);

		while ($row = $this->db->sql_fetchrow($result))
		{
			$session_time	= (!empty($session_times[$user_id])) ? $session_times[$user_id] : 0;
			if ($row['user_lastvisit'] == 0)
			{
				$last_visit = $this->language->lang('NO_VISIT');
			}
			else
			{
				$last_visit = (!empty($session_time)) ? $session_time : $row['user_lastvisit'];
				$last_visit = $this->user->format_date($last_visit);
			}
		}

		$this->db->sql_freeresult($result);

		return $last_visit;
	}
Thanks. Just, sorry to ask.. where do I put this code exactly?

User avatar
david63
Registered User
Posts: 16162
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Last visit info is NOT right update

Post by david63 » Thu Feb 07, 2019 1:02 pm

Car2013 wrote:
Thu Feb 07, 2019 12:56 pm
where do I put this code exactly?
Not a clue - it depends on what you are trying to do - it probably will not work "out of the box" anyway, you will have to tweak it to make it work in your situation as I have taken it from one of my extensions.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Car2013
Registered User
Posts: 87
Joined: Fri Nov 22, 2013 5:18 am

Re: Last visit info is NOT right update

Post by Car2013 » Thu Feb 07, 2019 8:30 pm

Oh man. I have exactly no idea ;)

Car2013
Registered User
Posts: 87
Joined: Fri Nov 22, 2013 5:18 am

Re: Last visit info is NOT right update

Post by Car2013 » Mon Feb 11, 2019 12:38 am

Guys... Any light about the subject?
I really dont know how to aply or even start..

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1047
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Last visit info is NOT right update

Post by mrgoldy » Tue Feb 12, 2019 11:39 am

What version of phpBB are you using and what style?
As <dt>{L_VISITED}:</dt> <dd>{VISITED}</dd> is nowhere to be found in the core code.
Or VISITED in general for that matter.

The part you are refering to is, by default:

Code: Select all

<dl class="details">
	<!-- EVENT memberlist_view_user_statistics_before -->
	<dt>{L_JOINED}{L_COLON}</dt> <dd>{JOINED}</dd>
	<dt>{L_LAST_ACTIVE}{L_COLON}</dt> <dd>{LAST_ACTIVE}</dd>
So what phpBB version are you using?
What style are you using?
Have you made core edits?
What extensions do you have installed?
phpBB Studio / ''Proud member of the Studio"

Car2013
Registered User
Posts: 87
Joined: Fri Nov 22, 2013 5:18 am

Re: Last visit info is NOT right update

Post by Car2013 » Wed Feb 13, 2019 8:28 pm

mrgoldy wrote:
Tue Feb 12, 2019 11:39 am
What version of phpBB are you using and what style?
As <dt>{L_VISITED}:</dt> <dd>{VISITED}</dd> is nowhere to be found in the core code.
Or VISITED in general for that matter.

The part you are refering to is, by default:

Code: Select all

<dl class="details">
	<!-- EVENT memberlist_view_user_statistics_before -->
	<dt>{L_JOINED}{L_COLON}</dt> <dd>{JOINED}</dd>
	<dt>{L_LAST_ACTIVE}{L_COLON}</dt> <dd>{LAST_ACTIVE}</dd>
So what phpBB version are you using?
What style are you using?
Have you made core edits?
What extensions do you have installed?
Well. Im using 3.2.5... prosilver.
About edits... Im not sure. Almost sure..that not.
Last edited by Car2013 on Thu Feb 14, 2019 4:23 pm, edited 1 time in total.

User avatar
david63
Registered User
Posts: 16162
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Last visit info is NOT right update

Post by david63 » Wed Feb 13, 2019 8:57 pm

Car2013 wrote:
Wed Feb 13, 2019 8:28 pm
Well. Im using 3.0.14
You do realise that all support, except for upgrading, of phpBB 3.0 ceased years ago
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Post Reply

Return to “phpBB Custom Coding”