/    Sign up×
Community /Pin to ProfileBookmark

Auto logout after certain time

I just noticed, if i login to my site, leave, and get back a hour later, am still logged in.

How can i make it so the user gets logged out automaticly after like half a hour?

am using sessions atm, if that matters.

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@bokehDec 01.2005 — That depends how the log in system works. If it uses php sessions just delete the session from the server. Closing the browser also does the same thing as far as the client is concerned. If log in is related to a cookie change the life of the cookie. Also consider having a definative log out feature.
Copy linkTweet thisAlerts:
@acemoauthorDec 01.2005 — It works with sessions now.. But seems like i will need to use cookies to make users log if there unactive for half a hour?

Could u give an example of how that works with cookies?
Copy linkTweet thisAlerts:
@bokehDec 01.2005 — A Cookie would be used so the user is remembered over a longer period and hence does not need to log in on each visit. To log someone out and destroy the session you need something like the following:
[code=php]<?php # logout.php
session_start();
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-86400, '/');
}
session_destroy();

# now redirect them to another page
?>[/code]
Copy linkTweet thisAlerts:
@acemoauthorDec 01.2005 — Oh, ok.. I got it like this now, I login, close my firefox, open firefox, go to the site again, and find myself still logged in.

This would give other ppl the possibility to get on my account if i would access the site on a public computer and close the browser instead of logging out.
Copy linkTweet thisAlerts:
@bokehDec 01.2005 — That's just the way things are. If someone does not logout properly there is nothing you can do except wait for the session to timeout. The only other way might be some annoying and unreliable piece of javascript.
Copy linkTweet thisAlerts:
@bokehDec 01.2005 — Oh, ok.. I got it like this now, I login, close my firefox, open firefox, go to the site again, and find myself still logged in.

This would give other ppl the possibility to get on my account if i would access the site on a public computer and close the browser instead of logging out.[/QUOTE]
By the way it's no good just closing the window, you must close the browser comletely. All browser windows closed. The session will then still be active on the server but not the client.
Copy linkTweet thisAlerts:
@acemoauthorDec 01.2005 — Ohh, thats something will not happen on this pc, lol got always 5+ firefox tabs open

But on a public pc, i'd login, do my stuff, close the browser and am logged.

Thats ok ?
Copy linkTweet thisAlerts:
@bokehDec 01.2005 — Ohh, thats something will not happen on this pc, lol got always 5+ firefox tabs open

But on a public pc, i'd login, do my stuff, close the browser and am logged.

Thats ok ?[/QUOTE]
Yes but the session still exists on the server even though it is over on the client. That means if someone has intercepted the session ID they could keep that session active indefinately.
Copy linkTweet thisAlerts:
@acemoauthorDec 01.2005 — are script kiddies able to do that?
Copy linkTweet thisAlerts:
@bokehDec 01.2005 — In a word, yes.
Copy linkTweet thisAlerts:
@acemoauthorDec 01.2005 — how to protect against the interception of an session id?
Copy linkTweet thisAlerts:
@bokehDec 01.2005 — Use an SSL (https) connection.
×

Success!

Help @acemo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...