[BETA] User Online Time

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Scam Warning
Locked
ben2309
Registered User
Posts: 90
Joined: Mon Jul 21, 2008 2:49 pm
Location: Scotland :D

Re: [BETA] User Online Time

Post by ben2309 »

Since jimcarrel was thinking it could be a PHP issue i decided i would update the PHP version on my server to the latest to see if it would make a difference, since i am having the same "resets to 0" problem.

I was on 5.2.1 and i updated to 5.2.6 but nothing. Same problem.

I was going to go back to 5.0.0 and 4.4.8 but i figured it would be too much hassle re-configuring apache and everything.

xxxgamer, can you tell us what phpBB version and what PHP verion you have?

I will have a read over the code and see if i can find some flawed logic somewhere or if some variables have been renamed in phpBB since this mod was created.
IF YOU VALUE YOUR PRIVACY, SAY NO TO PHORM.
SIGN THE PETITION, CLICK HERE.


Phorm is adware, and your ISPs want to force it on you. Tell them to go eat their own heads.

http://www.badphorm.co.uk/
updown
Registered User
Posts: 542
Joined: Sat Jan 05, 2008 6:53 am

Re: [BETA] User Online Time

Post by updown »

I run this since phpbb-version 3.0.0, with 3.0.1 and now with 3.0.2 and it works proper!

Before 3.0.1, my servers run with php4, after that I switched to php5.2.5 without any problems.

The only problem ever occured while auto-updating from 3.0.0 to phpbb version 3.0.1 - some of the former code-changes have been merged away automatically, so they needed to be edit afterwards again. So the only hint I can give, is: Check your edits...
ben2309
Registered User
Posts: 90
Joined: Mon Jul 21, 2008 2:49 pm
Location: Scotland :D

Re: [BETA] User Online Time

Post by ben2309 »

What mod version are you using?
IF YOU VALUE YOUR PRIVACY, SAY NO TO PHORM.
SIGN THE PETITION, CLICK HERE.


Phorm is adware, and your ISPs want to force it on you. Tell them to go eat their own heads.

http://www.badphorm.co.uk/
updown
Registered User
Posts: 542
Joined: Sat Jan 05, 2008 6:53 am

Re: [BETA] User Online Time

Post by updown »

uhmm, the latest 0.1.2 (beta 2) from first page - are there other ones?

As I can remember, the problems while updating occured in the session.php-edits - and there also seems to be the time-storage-problem of the others.
ben2309
Registered User
Posts: 90
Joined: Mon Jul 21, 2008 2:49 pm
Location: Scotland :D

Re: [BETA] User Online Time

Post by ben2309 »

This post as been deemed completely wrong so i have edited it away. Check below for some solutions.
Last edited by ben2309 on Wed Jul 23, 2008 10:43 pm, edited 1 time in total.
IF YOU VALUE YOUR PRIVACY, SAY NO TO PHORM.
SIGN THE PETITION, CLICK HERE.


Phorm is adware, and your ISPs want to force it on you. Tell them to go eat their own heads.

http://www.badphorm.co.uk/
updown
Registered User
Posts: 542
Joined: Sat Jan 05, 2008 6:53 am

Re: [BETA] User Online Time

Post by updown »

This is how my part of session.php look around the modification:

Code: Select all

					if (!$session_expired)
					{
						// Only update session DB a minute or so after last update or if page changes
						if ($this->time_now - $this->data['session_time'] > 60 || ($this->update_session_page && $this->data['session_page'] != $this->page['page']))
						{
							$sql_ary = array('session_time' => $this->time_now);

							if ($this->update_session_page)
							{
								$sql_ary['session_page'] = substr($this->page['page'], 0, 199);
								$sql_ary['session_forum_id'] = $this->page['forum'];
							}

							$db->sql_return_on_error(true);

							$sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
								WHERE session_id = '" . $db->sql_escape($this->session_id) . "'";
							$result = $db->sql_query($sql);

							$db->sql_return_on_error(false);

// User Online Time
							if ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER) //only for registered members
							{
								$time_diff = $this->time_now - $this->data['session_time'];
								//if the difference is more than 10 mins then give the user a grace 10 minutes as online time, as session existed, meaning the user did not log out... we should imagine that the user WAS online for some time after the last click
								$seconds_to_add = ($time_diff > 600) ? 600 : $time_diff;
								$this->data['user_online_time'] += $seconds_to_add;
								$sql = 'UPDATE ' . USERS_TABLE . ' SET user_online_time = ' . $this->data['user_online_time'] . '
									WHERE user_id = ' . $this->data['user_id'];
								$db->sql_query($sql);
								unset($time_diff);
								unset($seconds_to_add);
							}
//END User Online Time

							// If the database is not yet updated, there will be an error due to the session_forum_id
							// @todo REMOVE for 3.0.2
							if ($result === false)
							{
								unset($sql_ary['session_forum_id']);

								$sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
									WHERE session_id = '" . $db->sql_escape($this->session_id) . "'";
								$db->sql_query($sql);
							}
						}
//-- User Online Time
						else //special checks to be done if the user has returned within 1 min and on the same page
						{
							if ($this->data['user_id'] != ANONYMOUS && $this->data['user_type'] == USER_IGNORE) //for bots
							{
								//give them the exact time even if its less than 1 min... if its more than 1 min ignore as bots wont return after 1 min
								$seconds_to_add = $this->time_now - $this->data['session_time'];
								$seconds_to_add = ($seconds_to_add > 60) ? 0 : $seconds_to_add;
								if ($seconds_to_add)
								{
									$this->data['user_online_time'] += $seconds_to_add;
									$sql = 'UPDATE ' . USERS_TABLE . ' SET user_online_time = ' . $this->data['user_online_time'] . '
									WHERE user_id = ' . $this->data['user_id'];
									$db->sql_query($sql);
								}
								unset($seconds_to_add);
							}
							else if ($this->data['user_id'] != ANONYMOUS && $this->data['user_type'] != USER_INACTIVE) //this is only for the sake of displaying incremented time to the registered user. The added time is not updated in db.
							{
								$this->data['user_online_time'] += $this->time_now - $this->data['session_time'];
							}
						}
//-- END User Online Time
						$this->data['is_registered'] = ($this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER)) ? true : false;
						$this->data['is_bot'] = (!$this->data['is_registered'] && $this->data['user_id'] != ANONYMOUS) ? true : false;
						$this->data['user_lang'] = basename($this->data['user_lang']);

						return true;
					}
				}
				else
				{
					// Added logging temporarly to help debug bugs...
					if (defined('DEBUG_EXTRA') && $this->data['user_id'] != ANONYMOUS)
					{
						if ($referer_valid)
						{
							add_log('critical', 'LOG_IP_BROWSER_FORWARDED_CHECK', $u_ip, $s_ip, $u_browser, $s_browser, htmlspecialchars($u_forwarded_for), htmlspecialchars($s_forwarded_for));
						}
						else
						{
							add_log('critical', 'LOG_REFERER_INVALID', $this->referer);
						}
					}
				}
			}
		}

		// If we reach here then no (valid) session exists. So we'll create a new one
perhaps this helps...
ben2309
Registered User
Posts: 90
Joined: Mon Jul 21, 2008 2:49 pm
Location: Scotland :D

Re: [BETA] User Online Time

Post by ben2309 »

Correct, that makes no sense now i look at it. I somehow managed to get the edits the wrong way round (no ruddy idea how), then shuffle one around and then it worked :? so i undid it and tried again and its now working!

That has completely confused me, regarding that reset error and i guess it just leaves us at the point - check your edits! :lol:
IF YOU VALUE YOUR PRIVACY, SAY NO TO PHORM.
SIGN THE PETITION, CLICK HERE.


Phorm is adware, and your ISPs want to force it on you. Tell them to go eat their own heads.

http://www.badphorm.co.uk/
jimcarrel
Registered User
Posts: 671
Joined: Fri Jul 27, 2007 10:49 pm
Location: Oklahoma City, Oklahoma

Re: [BETA] User Online Time

Post by jimcarrel »

ben2309,
So are you running phpBB3 version 3.0.2? The code looks like 0.2, but I had to ask to make sure.
My install that has always worked, ( the crazy one that I mentioned that had no edits in session.php)
quit when I upgraded to 3.0.2.
Yet yours is still working after upgrading 3.0.1?
Mine stopped working at upgrading, and it still yet shows the hours online that were there when it quit working.
I guess it is not a clock "that takes a beating, and keeps on ticking".
This has got to be one of the simplest as far as edits to make, but also the darndest to edit right.
Grace--Getting what I don't deserve
Mercy--Not getting what I do deserve
jimcarrel
Registered User
Posts: 671
Joined: Fri Jul 27, 2007 10:49 pm
Location: Oklahoma City, Oklahoma

Re: [BETA] User Online Time

Post by jimcarrel »

updown,
I am very encouraged now, (may not be a problem with php version after all :oops: ) I added your edits for Online time (into the session.php of the install that quit logging timeafter upgrading to phpBB3 3.0.2) and it has started advancing time again. (yahooooo).

***(just a note here. the one that quit working, maybe because after upgrading, I never checked to be sure edits were still there. Ha, I have to many forums to tend. )

So I am going to reinstall it in the forum that has never worked. Could be that my hard head was always too sure I put the edits in the right place, even after checking and checking and rechecking.

I will let you know.
Last edited by jimcarrel on Thu Jul 24, 2008 4:00 am, edited 1 time in total.
Grace--Getting what I don't deserve
Mercy--Not getting what I do deserve
jimcarrel
Registered User
Posts: 671
Joined: Fri Jul 27, 2007 10:49 pm
Location: Oklahoma City, Oklahoma

Re: [BETA] User Online Time

Post by jimcarrel »

Considering what updown has given us, maybe we should repost some "correct and easier" finds for session.php. I could do it by tomorrow evening with credit given to updown, of if updown wishes to do it, go ahead.
What say ye?
Grace--Getting what I don't deserve
Mercy--Not getting what I do deserve
xxxgamer
Registered User
Posts: 574
Joined: Mon Jul 16, 2007 11:25 pm

Re: [BETA] User Online Time

Post by xxxgamer »

Well guys im using phpbb 3.00 and would like the counter to reset. Is that possible on my version of phpbb?
jimcarrel
Registered User
Posts: 671
Joined: Fri Jul 27, 2007 10:49 pm
Location: Oklahoma City, Oklahoma

Re: [BETA] User Online Time

Post by jimcarrel »

xxxgamer,
Seeing as how, some of us got that by accident, accidents are hard to figure out.
I don't have a clue as to how you could do that on purpose.
Your Idea sounds like a Mod for a Mod.
:)
Grace--Getting what I don't deserve
Mercy--Not getting what I do deserve
jimcarrel
Registered User
Posts: 671
Joined: Fri Jul 27, 2007 10:49 pm
Location: Oklahoma City, Oklahoma

Re: [BETA] User Online Time

Post by jimcarrel »

These are my "Finds" for the includes/session.php file. Credit to be given to " updown "
I checked them several times, and there is only one find per find, no "second finds".

Open includes/session.php and find:

Code: Select all

$sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
								WHERE session_id = '" . $db->sql_escape($this->session_id) . "'";
							$result = $db->sql_query($sql);

							$db->sql_return_on_error(false);
The end of that find should land you around line 339 or very close.

On a new line AFTER the previous find, ADD

Code: Select all

// User Online Time
                     if ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER) //only for registered members
                     {
                        $time_diff = $this->time_now - $this->data['session_time'];
                        //if the difference is more than 10 mins then give the user a grace 10 minutes as online time, as session existed, meaning the user did not log out... we should imagine that the user WAS online for some time after the last click
                        $seconds_to_add = ($time_diff > 600) ? 600 : $time_diff;
                        $this->data['user_online_time'] += $seconds_to_add;
                        $sql = 'UPDATE ' . USERS_TABLE . ' SET user_online_time = ' . $this->data['user_online_time'] . '
                           WHERE user_id = ' . $this->data['user_id'];
                        $db->sql_query($sql);
                        unset($time_diff);
                        unset($seconds_to_add);
                     }
//END User Online Time
This next find is a block of code that is right between the two online time edits. The end of this find should land you on about line 366 or very close.

Find

Code: Select all

// If the database is not yet updated, there will be an error due to the session_forum_id
							// @todo REMOVE for 3.0.2
							if ($result === false)
							{
								unset($sql_ary['session_forum_id']);

								$sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
									WHERE session_id = '" . $db->sql_escape($this->session_id) . "'";
								$db->sql_query($sql);
							}
						}
On a new line, After the above find, add

Code: Select all

//-- User Online Time
                  else //special checks to be done if the user has returned within 1 min and on the same page
                  {
                     if ($this->data['user_id'] != ANONYMOUS && $this->data['user_type'] == USER_IGNORE) //for bots
                     {
                        //give them the exact time even if its less than 1 min... if its more than 1 min ignore as bots wont return after 1 min
                        $seconds_to_add = $this->time_now - $this->data['session_time'];
                        $seconds_to_add = ($seconds_to_add > 60) ? 0 : $seconds_to_add;
                        if ($seconds_to_add)
                        {
                           $this->data['user_online_time'] += $seconds_to_add;
                           $sql = 'UPDATE ' . USERS_TABLE . ' SET user_online_time = ' . $this->data['user_online_time'] . '
                           WHERE user_id = ' . $this->data['user_id'];
                           $db->sql_query($sql);
                        }
                        unset($seconds_to_add);
                     }
                     else if ($this->data['user_id'] != ANONYMOUS && $this->data['user_type'] != USER_INACTIVE) //this is only for the sake of displaying incremented time to the registered user. The added time is not updated in db.
                     {
                        $this->data['user_online_time'] += $this->time_now - $this->data['session_time'];
                     }
                  }
//-- END User Online Time
That should fix you up as far to the session.php edits.
Grace--Getting what I don't deserve
Mercy--Not getting what I do deserve
Novaslash
Registered User
Posts: 11
Joined: Sat May 31, 2008 11:53 am

Re: [BETA] User Online Time

Post by Novaslash »

updown > Now is good. What you said a little earlier for sessions.php, I had placed a few lines lower. Any refonctionne.

Thank you very much ^^
I apologise for my English!
updown
Registered User
Posts: 542
Joined: Sat Jan 05, 2008 6:53 am

Re: [BETA] User Online Time

Post by updown »

glad to hear this helped!

The irony of this is, that I'm using this mod only internally, viewable only by admins - since I really don't want my members to realize how much time (mostly months) of their life they have already spent on the board. As you can easily imagine: this can be contraproductive :lol:
Locked

Return to “[3.0.x] MODs in Development”