Topic: Session Timeout Auto Logout...

Hi Good Folks,
  Sorry to bother about this, I just couldn't find the answer...

The Problem:
- User walks away from the workstation... session never times out
- User closes browser, comes back later... gets right in without login

The three solutions I have seen are:
- set this in the user's profile

...and then I did find this...
===========================
http://punbb.org/forums/viewtopic.php?pid=55287
Can i set cookie of punbb  which expires after user .. closes the Internet Explorer Window .. ??.
One answer was...
In functions.php

Search for: (about Line 151)
setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure);

and replace it with:
setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), 0, $cookie_path, $cookie_domain, $cookie_secure);

---------------------------
Comment by dev'r: DO NOT DO THIS.. WILL NOT WORK....
Search for
    $expire = $now + 31536000;    // The cookie expires after a year
and replace with
    $expire = 0;    // The cookie expires when session ends
===================================

I tried these things but its not working.
What I wish to do is Globally Set the situation so after about a half hour, no ifs ands or buts, no matter how the user, even the admin, sets up their personal settings, no matter if they leave the browser open or not, ....if there is no activity for about a half hour I want that session to time out and require a log in to get back in.

How can I accomplish this?
I am still using 1.2.12 (or .15... cannot recall offhand, I just haven't had time to do the upgrades... so many mods to watch out for breaking something that isn't broken just now ;^)  Just not enough time.

Best regards,
Rick / TwoHawks

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

You then set the time to time() + 1800 rather than to 0.

3 (edited by twohawks 2008-04-15 22:00)

Re: Session Timeout Auto Logout...

Hi Smartys.  Thanks. 

I am still observing results different than expected. Please allow me to explain and try to obtain better clarity as to how this should work..

First, to be clear, I reset everything back to how it was originally (i.e., stock, or when downloaded).

Now let me see if I understand this proper...
If, right near the beginning of functions.php file where "cookie stuff" is setup...
$now = time()  (no changes made)
and then $expire is changed to something like  "= $now + #;" ...where # is some number representing seconds,
..then what should happen is the session cookie should expire after the # of seconds set, and also if/when the browser is closed...
Is this correct?

If so, some questions remain...
1) I do observe the session requiring login after closing and then reopening the browser, so no question there (except I do not know why it was not doing this before [smegma?].
2) I do not observe the session timing out (resetting and requiring a login) after  "#" of seconds of user inactivity.  Why is this?  Can I change it?
3) I do not observe the session resetting if I close a browser tab?  Can I enforce that?
4) How is any of this possibly related to "Save Username and Password between visits" setting in user's profile:privacy, and how would I over-ride that?

Cheers (and thanks for your, as always, indefatigable support ;^),
TwoHawks

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

..then what should happen is the session cookie should expire after the # of seconds set, and also if/when the browser is closed...
Is this correct?

No. You either have a cookie that expires after a set number of seconds or a cookie that expires when the browser closes. Not both (you can have both, but it involves more server side code).

1. I don't know why that would be. Keep in mind you're not just changing this one place in the code, the assumption is all over.
2. That was what you should be doing by editing files in the way I described.
3. No
4. Instead of doing the ternary statement, you just set it to a constant time() + 1800.

Re: Session Timeout Auto Logout...

Hmmmm..  I am not obtaining expected results...
Per #1) when you say "all over", I assume you mean limited to "in the function.php file", is this correct?

Per#2) I set it up as "$expire = $now + 1;" for testing.  Since "$now = time();" I assume this all means that the cookie knows the expiry time will be one second after I log in.
I also assume that this means that if after one second of being logged in I refresh the page, the cookie will be queried and the "session will know the time has passed" and require me to log back in.
But this does not happen... I remain logged in until I either log out or close the browser entirely and then re-open it.  I have tried differnt settings for $expire and I continue to get the same results.

What am I missing here?

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

No, when I say "all over" I mean "anywhere where we're setting a login cookie"

Re: Session Timeout Auto Logout...

Okay.  Well, I located those files and, along with the changes mentioned above [post#5 regarding editing in functions.php file], I changed each occurance of "time() + xxxxxxx"  in the other files (where it related to cookie stuff) to "time() + 1" ,
...but the user still stays logged in after a lengthy idle time :^(

Just to mention, for testing I use a separate browser that is storing its own cookies, and  I log the user instance out, and then log it back in.  I can see the "end of session" cookies being set each time I log the user instance in.

`8^|

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

If all you're doing is replacing time() + 31536000 with time() + 1, then you're doing it wrong. Expiration is still set to 0 if save_pass is disabled. I was fairly clear that you needed to replace the entire ternary statement, not just change one output wink

Re: Session Timeout Auto Logout...

<twohawks rubbs his eyeglasses, ponders 'basic reading skills 101'>....

Let me get back to you  ...8^P

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

All righty then... I'm in the saddle now - thank you so much, Smartys!

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

No problem, glad to hear it's working smile

Re: Session Timeout Auto Logout...

Woops... I cannot figure out this next thing.
I thought it was all good, but then while the user is active in the session, no matter, when the time is up the user's session is killed.
  Which where is the 'right place' to set it so that the session stays active as long as the user does something within the timeout period set?

Now it would seem to me that..
1) Whenever an action is taken there is a flow through common.php and functions.php, and
2) so it seems check_cookie() function in common.php gets triggered on any event, such as clicking a link to another page, and then
3) that function is them run from functions.php, which
4) sets the "new $now()" time
5) which then updates the value in $expire = $now + 1800; (that I have configured there.
6) which should be getting used on down the line - thus keeping the cookie time 'within bounds'.

Or something like that - no?

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

Which where is the 'right place' to set it so that the session stays active as long as the user does something within the timeout period set?

check_cookie, as you guessed.

Re: Session Timeout Auto Logout...

Well,
Kindly forgive me for intruption, But Smartys is not this all possible (whatever twohawks wants except auto log-out for certain no of idle minutes) if the user dont view  "Save Username and Password between visits" setting in user's profile:privacy form, or while completing the registration process. & internally the administrator sets this setting as disabled globally for all., If yes than how to disable this setting permanently & hide the "Save Username and Password between visits" setting in user's profile:privacy form & also in registration form.

Re: Session Timeout Auto Logout...

Divnain: Yes.
To hide the option, you need to edit register.php and profile.php to remove not only the option but the PHP that allows you to set it. Then, you run an update command to set save_pass to 0 on the users table. Then I think you're set.

16 (edited by twohawks 2008-04-16 23:46)

Re: Session Timeout Auto Logout...

Smartys wrote:

Which where is the 'right place' to set it so that the session stays active as long as the user does something within the timeout period set?

check_cookie, as you guessed.

Nope, I think that's not correct.
In fact, it appears that, in the functions.php file (which definitely gets called for a cookie check via common.php anytime we do things)
...the cookie gets updated (pun_setcookie) only if authentication fails.  So either the 'so-called'  timer runs out, or the user set save_pass so the timer does not matter

So in fact, it appears there is no code written there that checks the updated $expire time(r), and then updates the cookie with the new $expire value!

So if I didn't overlook somethng or misunderstnad the check_cookie functionality, then it would seem I need to write a little bit of code that will do just that.

Your input on this is most welcome.

(Oh and @Divnain, yeah, I already took care of all that, thanks.)

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

twohawks: My point was that check_cookie is the proper place for YOU to put in that functionality, not that PunBB does it. I misunderstood your post (the part that I quoted) as referring to setting the cookie as opposed to setting the expiration time for a cookie.

Re: Session Timeout Auto Logout...

All righty then... now that I'm on track, can you tell me, can I simply reset the expire value inthe cookie and leave the rest, or do I have to re-write all values to the whole thing?

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

You have to call pun_setcookie with the same parameters, just change the expire parameter to the new time.

20 (edited by twohawks 2008-04-16 23:52)

Re: Session Timeout Auto Logout...

So IOW, ...

So then I can get away with
pun_setcookie(, , $expire);

Or Must I do:
pun_setcookie($cookie['user_id'], $cookie['password_hash'], $expire);

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

Right, PHP doesn't magically let you leave out parameters wink

Re: Session Timeout Auto Logout...

LOL... hey chief, thanks for all your guidance.

TwoHawks
Love is the Function
No Form is the Tool

Re: Session Timeout Auto Logout...

No problem, glad to help smile