Jump to content

Session Time Out Questions


pengu

Recommended Posts

I have a few questions.

 

First one is about phpBB forums, as an example.  You log in, do your thing and exit the browser, now it will still say you're logged in for a period of 5-10 minutes or so, even though you have exited via the browser.  After that time period it will then say you're not still logged in, while checking the users.

 

How is this achieved?  Because I thought a field in the phpBB_Users would be updated and from my understanding the only way to change that is to trigger it, via a logout button.

 

My second question, I'd like to use MyBrute as an example, thinking of it in a database sort of view.  You get to do 3 fights a day, the next day this 3 fights thing is reset.  Can this be achieved automatically, say, through a script or would someone have to manually run a query every day?

 

Cheers,

Pengu.

Link to comment
Share on other sites

hai

for your first thing this can be achieved by some thing like this using the mysql tables.

when a user logs in a column will b updated with a value that the user is logged in let us consider the value to be updated as 1.

so who all users have the value 1 in that column they are meant to be as logged in users..

when the user click on loggout the value will be changed to 0. this means that the users with value zero wil be considered as logged out users.

 

regarding the second one.

 

this can be achieved by running an auto script like that of a cron which will automatically update the users to the three fights everyday at a particular time..

 

 

 

Link to comment
Share on other sites

who all users have the value 1 in that column they are meant to be as logged in users..

when the user click on loggout the value will be changed to 0. this means that the users with value zero wil be considered as logged out users.

 

Wut!? I NEVER use the logout button meaning that your website will show me as logged in ad infinitum if your code is screwed it may also mean I will not be able to login anymore ad infinitum. And why make it so difficult if it's so easy??

 

How is this achieved?  Because I thought a field in the phpBB_Users would be updated and from my understanding the only way to change that is to trigger it, via a logout button.

 

session_set_cookie_params(3600);//remain logged in for one hour
session_start();

Link to comment
Share on other sites

i dont think that will screw up anything..

 

It will if the OP queries

 

SELECT .. FROM users WHERE username = $username AND password = $password AND logged_in = 0

 

Which will return no results as he is still logged in.

 

AND logged_in = 0

 

Is not so uncommon if you want to disallow re-login. Anyway there are better and more efficient ways to do this:

 

1)

 

session_set_cookie_params(3600);//remain logged in for one hour
session_start();

 

2) A sessions table

 

sessions (id, user_id, date_last_modified, lifetime)

Link to comment
Share on other sites

Hi Ignace thanks for that... BUT cookies wont show 'WHO IS ONLINE' sort of thing will it?  Because it doesn't update the table. Right?  :confused:

 

I will Google cron, this is server side I'm assuming.

Link to comment
Share on other sites

I would think the easiest way to do this would be to have a column in the user table called, oh, I don't know, "LastAccess".  Every time the user accesses any page, update this column to NOW().  When you want to know how many users are logged in, select a count of users where LastAcccess is greater than NOW() - 5 minutes (or whatever time frame you want). 

 

As for the 3-a-day thing.  That needs 2 columns in the user table, LastFightDay, and DayFightCount.  If LastFightDay is today and DayFightCount is less than 3, then let them fight and increment the count.  If LastFightDay is before today, set the count to zero, change the Day to today, let them fight and increment the count.

 

 

Link to comment
Share on other sites

I would think the easiest way to do this would be to have a column in the user table called, oh, I don't know, "LastAccess".  Every time the user accesses any page, update this column to NOW().  When you want to know how many users are logged in, select a count of users where LastAcccess is greater than NOW() - 5 minutes (or whatever time frame you want). 

 

As for the 3-a-day thing.  That needs 2 columns in the user table, LastFightDay, and DayFightCount.  If LastFightDay is today and DayFightCount is less than 3, then let them fight and increment the count.  If LastFightDay is before today, set the count to zero, change the Day to today, let them fight and increment the count.

 

Thanks, first part is helpful.

 

I believe a cron job thru cpanel will do what I want, I would not, in this case at least, want to increment the values. 

The would always be set to 3 at XXXX hours

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.