[web] Getting last visit time for custom forum script

Started by
4 comments, last by Coward 18 years, 12 months ago
I am having serious issues trying to figure out how to do this. I have the timestamp updated in the user's row in the db each page load. With the following code:

		$time = time();
		$sql = "UPDATE `os_users` SET `user_lastlogin` = '". $time ."' WHERE `user_id`= '".$db->escape_string($_SESSION['user_id'])."' LIMIT 1";
		$result = $db->query($sql);

Now what do I need to do from there to get the last time they visited?
Advertisement
You mean this?
"SELECT `user_lastlogin` FROM `os_users` WHERE `user_id`= ".$db->escape_string($_SESSION['user_id'])."' LIMIT 1"
No, that won't work since it is updated for every page view. I am using this for new posts since last visit for forums.
...I suggest you fish through the phpbb code, there is no truely efficient way of doing this, as far as i've seen, unless you can rig up a session array(huge strain on server though)
This might sound a bit lame, but why are updating last_login every page view? Visitors don't login again every single page.
I would suggest you use two fields: last_login and last_pageview. Or save their session id to see if they been away for a while (not the most precise method ofcourse).
In your login script, set a session varible to the lastlogin time, before you update the database.
Don't Temp Fate..

This topic is closed to new replies.

Advertisement