473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to automatically logout users from my site

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??
Jan 19 '08 #1
5 2560
Hello,

ca*******@gmail.com 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
Jan 19 '08 #2
On Jan 19, 11:03*pm, camili...@gmail.com 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.
Jan 19 '08 #3
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.
Jan 20 '08 #4
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.
Jan 20 '08 #5
On Sun, 20 Jan 2008 00:03:14 +0100, <ca*******@gmail.comwrote:
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
Jan 20 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: gary thomson | last post by:
Apologies if this is not quite the correct ng to be asking this question and sorry to be so vague in what I'm asking, but can anyone give me any pointers to implementing a logout button from a...
1
by: Tuan | last post by:
Hi, I am writting a small web application and I want to create a logout page for the users like the logout on yahoo. If the users logout they cannot go back by using back button history on the...
6
by: Kevin Yu | last post by:
is it possible to for user to click a logout button to logout and when the user want to get into the system again, the user have to login again? Kevin
4
by: JessyEzzy | last post by:
I am working on this site in which users have to login first to access the site pages, after a user performs a login a record for this user is inserted in a table of online users. When a user...
25
by: crescent_au | last post by:
Hi all, I've written a login/logout code. It does what it's supposed to do but the problem is when I logout and press browser's back button (in Firefox), I get to the last login page. In IE,...
0
by: deneb | last post by:
Hello all? When I restart the page or just logout the page, cookie file is deleted automatically. What's wrong with me?? here is my code. ' If I success in Login process, Save user ID in...
1
by: Adrock952 | last post by:
I have a link on my site which obviously says "Login" where users log in. I would like that link to be changed to "Logout" when the user has successfully logged in and the session has been created...
3
by: kashok | last post by:
hi, how to track users login/logout time on our site and store it in database Thank U Ashok
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.