Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

how to automatically logout users from my site

 
   Database Forums (Home) -> PHP RSS
Next:  webpage hit counter in PHP  
Author Message
camilin87

External


Since: Jan 19, 2008
Posts: 1



(Msg. 1) Posted: Sat Jan 19, 2008 3:03 pm
Post subject: how to automatically logout users from my site
Archived from groups: comp>lang>php (more info?)

hello.
I'm building a site using php I have a setup.php page wich has at the
begining session_start();
and every single page from my site includes setup.php. When a user
registers I save in $_SESSION["Login"] the userName, so that when !
isset($_SESSION["Login"]) I can redirect him to the login.php page.
After some inactivityperiod, e.g. 20 min, I need that user to be
automatically logged off. Besides I need to keep track of the users
that are online in that moment, so the logout should run some server-
side script too. Can anyone give me some ideas??

 >> Stay informed about: how to automatically logout users from my site 
Back to top
Login to vote
ajtrichards

External


Since: Jan 19, 2008
Posts: 6



(Msg. 2) Posted: Sat Jan 19, 2008 3:52 pm
Post subject: Re: how to automatically logout users from my site [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 19, 11:03 pm, wrote:
> hello.
> I'm building a site using php I have a setup.php page wich has at the
> begining session_start();
> and every single page from my site includes setup.php. When a user
> registers I save in $_SESSION["Login"] the userName, so that when !
> isset($_SESSION["Login"]) I can redirect him to the login.php page.
> After some inactivityperiod, e.g. 20 min, I need that user to be
> automatically logged off. Besides I need to keep track of the users
> that are online in that moment, so the logout should run some server-
> side script too. Can anyone give me some ideas??

You could save the username as a cookie and set a expiry time e.g
setcookie("username", "user", "/", "EXPIRY TIME");

Then for each page they load do a setcookie to keep it refreshed with
the timelimit.

 >> Stay informed about: how to automatically logout users from my site 
Back to top
Login to vote
Jensen Somers

External


Since: Jan 18, 2008
Posts: 6



(Msg. 3) Posted: Sun Jan 20, 2008 12:35 am
Post subject: Re: how to automatically logout users from my site [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hello,

wrote:
> hello.
> I'm building a site using php I have a setup.php page wich has at the
> begining session_start();
> and every single page from my site includes setup.php. When a user
> registers I save in $_SESSION["Login"] the userName, so that when !
> isset($_SESSION["Login"]) I can redirect him to the login.php page.
> After some inactivityperiod, e.g. 20 min, I need that user to be
> automatically logged off. Besides I need to keep track of the users
> that are online in that moment, so the logout should run some server-
> side script too. Can anyone give me some ideas??

I handle things very basic and easily. I have a session class which holds all the
information I need to save in a session (user login details, current shopping
list items...) and one of those is the time when the session was created. When
the user moves to the next page one of the functions I call is one that checks
the current time against the saved session time. If the difference between those
is greater than time X I call the logout function and redirect the user to the
login form.

I don't really see a point in checking the login time of the user with some cron
job. If he wants to leave a page open for 2 hours that's fine, he can't do
anything special with it. If he closes the browser the session is destroyed, if
he moves to another page I have the checking routines.

- Jensen
 >> Stay informed about: how to automatically logout users from my site 
Back to top
Login to vote
Jonas Werres

External


Since: Nov 09, 2007
Posts: 17



(Msg. 4) Posted: Sun Jan 20, 2008 12:16 pm
Post subject: Re: how to automatically logout users from my site [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> You could save the username as a cookie and set a expiry time e.g
> setcookie("username", "user", "/", "EXPIRY TIME");
>
> Then for each page they load do a setcookie to keep it refreshed with
> the timelimit.

Yeah great. Or you do something that's not an enormous security hole,
since cookies can be freely created and edited by the user.

Running PHP scripts without the context of an HTTP request is only
possible by using cronjob s or similar things.
So the only thing you can do is saving timestamps of last activity (NOT
IN COOKIES!) and look every minute or so if there are expired ones.

If you would tell us what you are planing to do, we could tell you why
you don't want to do that.
 >> Stay informed about: how to automatically logout users from my site 
Back to top
Login to vote
Jonas Werres

External


Since: Nov 09, 2007
Posts: 17



(Msg. 5) Posted: Sun Jan 20, 2008 12:18 pm
Post subject: Re: how to automatically logout users from my site [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> I don't really see a point in checking the login time of the user with
> some cron job. If he wants to leave a page open for 2 hours that's fine,
The session is normally expired than

> he can't do anything special with it. If he closes the browser the
> session is destroyed,
No, it's not. There is no sure way for the server to determine if the
browser is closed. The session will continue to exist until it expires.
Only the browser will forget how to access it.
 >> Stay informed about: how to automatically logout users from my site 
Back to top
Login to vote
Rik Wasmus

External


Since: Sep 02, 2007
Posts: 210



(Msg. 6) Posted: Sun Jan 20, 2008 1:13 pm
Post subject: Re: how to automatically logout users from my site [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sun, 20 Jan 2008 00:03:14 +0100, wrote:

> hello.
> I'm building a site using php I have a setup.php page wich has at the
> begining session_start();
> and every single page from my site includes setup.php. When a user
> registers I save in $_SESSION["Login"] the userName, so that when !
> isset($_SESSION["Login"]) I can redirect him to the login.php page.
> After some inactivityperiod, e.g. 20 min, I need that user to be
> automatically logged off. Besides I need to keep track of the users
> that are online in that moment, so the logout should run some server-
> side script too. Can anyone give me some ideas??

Easiest way: define a database storage handler for the session (see
http://php.net/session_set_save_handler), use a table with a datetime or
timestamp field (always updated to the current time on save) and a
blob/text field for the session-data. Define a proper function for the
garbage-collector which uses the settings for a session
(session.gc_maxlifetime), and everything will be done automatically.
Getting information about current sessions now becomes a simple query on
the database.
--
Rik Wasmus
 >> Stay informed about: how to automatically logout users from my site 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Plugin system: Automatically instantiate included classes? - Hi there, I am planning to implement a plugin system, based on the observer pattern in some way, but now I am stuck with the instantiation of the plugins. I want the plugins to have their own class, abstracted from the class Plugin. So far its nothing....

need help with a new site - hell all, i'm starting a new wiki for programming called "CoderWiki" i plan on documenting all functions of all programming languages. I have started a couple portals for C, VB, PHP, HTML, Java, Smalltalk, etc, and just added a API Guide sec...

Review my site - please review my sites http://php.c-o.cc http://phpacme.co.cc http://phpacme.c-o.cc

Structure of a PHP-driven site - Hey everyone, I've been managing a few websites, all built around the same architecture, for several years now, but it's time to hand them off to someone else and I'm trying to "clean them up" before I go. It got me to wondering how other peo...

Site Search Pro Gold 2.0 - We have come across a typical problem with Site Search Pro Gold 2.0 - Any text/word/searchkey having apostrophe mark are not getting indexed by the system as the search result is not displaying any of them. For example: If we have a paragraph in a page ...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]