473,883 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling session destroy and logout issue. How to handle ?

60 New Member
Hi

This is somas here. I asked query about detecting the browser close event using javascript. I want to detect the event only when the X button in the top right corner is clicked and not else where. (like moving to other pages by clicking some links).
Can u help me in this case.

Cause of this ,

In my php site, i want to restrict multiple logins with same username and password at a same time from different system.
To avoid this , in backend i.e. postgres database , i created a table which has login (boolean) field. If a user logged in , that login flag is set to true. If any other user tries to log in with same user name and password , i'm restricting that login . (Since that user is already logged in) . If logout link is clicked , i'm calling a php page , there the login flag is reset and session variables are destroyed. So there would not be any problem. Incase , if the browser is closed using X button in the top right corner , these login flag resetting process would not take place. Then how that user can login again ? when i should clear this flag.

When the user is idle for long time , i'm destroying the session variables. For this i created a login_details table. It contains user_id, login_time, last_action_tim e. Whenever the user login i'm updating the login_time and last_action time with current_timesta mp. While moving to some other page , first i'm checking the last_action time with current_timesta mp, if the difference is greater than the session expiry time (normal variable which i explicitly declared. Not the session variable) , it is assumed that the user is idle .Hence the , login (boolean) flag is reset , session varaiables are destroyed (manaully giving that command) , and move to a page that displays session expiry message and tell the user to login .

Here also , what i should do if the browser X (close) button is clicked without proper logout ? Hence i'm hunting for javascript event on clicking X close button ?
Or is there any other efficient method to handle this.
Please post your replies. It is very urgent

Thanks in advance
somaskarthic
Aug 26 '06 #1
6 18232
ronverdonk
4,258 Recognized Expert Specialist
Why do you worry about that? Just stick with the procedure as you have it.

When a user clicks the X on the bowser, the user data in the database still shows him as 'logged in'. So the next time he comes back, just check the time of inactivity and force him to login again.

If you really want to delete the entry from the database, you can run a daily cron-job to remove any hanging user entries.

Ronald :cool:
Aug 26 '06 #2
bassamba
7 New Member
hello, i'm having the same problem, my solution is this:
When the user logs in, i set a boolean flag to 'yes' and update the timestamp in the DB to the login time.
if the user properly logs out, this boolean will be set 'no'.

Now, if a another person tries to login while the original user is logged in, the boolean will be validated and the login will fail.

the problem is: how to handle browser close issue.
i came up with this idea: i create a session variable that contains a timestamp of the user's last activity($_SESS ION['last_action']).
on each page load we execute the following:
Expand|Select|Wrap|Line Numbers
  1. if ( (current time - $_SESSION['last_action']) > $time_out_max )
  2. {
  3. //update the $_SESSION['last_action'] and set it to the current time
  4. // update the database and set the 'last_action' field to the current time.
  5. }
mean while, a cron job is executed regulary every certain amout of time ( larger that $time_out_max, let's call it $cron_time_out ).
if the 'last_action' field is larger the $cron_time_out (this means that user was inactive and most propably closed the browser) in this case we reset the account and set the boolean flag to 'no'.

incase that the user didn't close the browser but was inacative for a a period larger than $cron_time_out, we redirect her to the login page on the next page load.

is this efficient? tell me what do u think.
Oct 2 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
You can use this method, but it will put some load on your db server if you want to update each user action. But I hope you mean that last_action is actually the time the user loads another page.

Ronald :cool:
Oct 2 '06 #4
bassamba
7 New Member
But I hope you mean that last_action is actually the time the user loads another page.

Ronald :cool:
yes, that's what i meant


thanks ronald
Oct 15 '06 #5
ambanna
1 New Member
This is Ambu,
to reset the flag when user logs out or close the browser.

if he logs out as usual u can reset it in logout page but if he closes the browser

so you can write your code in global.asa file

the session_end in this section you can write your code reset the flag
Dec 8 '08 #6
Atli
5,058 Recognized Expert Expert
Hi Ambu.

Thank you for your suggestion.
Although you should note that this is a PHP forum, and unless I am very much mistaken, your suggesting is for old-school ASP applications.

ASP and PHP are two entirely different things, and although your suggestion might be perfect for a similar problem in ASP, I'm afraid it won't be as useful for a PHP application.
Dec 8 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
14663
by: Jeff | last post by:
I've searched the web for hours trying to figure out this problem and can't seem to find any pertinent answers. I have a website where the user starts on a login page, puts in their credentials and hits a submit button, which then takes the user to a 2nd PHP page which simply runs PHP code that checks the user's credentials from my database, and if authenticated creates a session, assigns a few session variables (including a session...
7
1489
by: Thaynann | last post by:
I am developin an application that access a web site, i can get to the first page of the site, but when i POST to get to other pages, it gives me a message (amongst the HTML code) "Session Timed Out" It doesnt happen in IE, unless i leave the site sitting for about 10mins (my code executes in under 10 mins) can anyone help me as to why this happens? Thanx in advance,
0
3950
by: TaeHo Yoo | last post by:
Hi all, I am prett new in asp.net. We have a project which has classic asp and asp.net scripts. Obviously this project has a bin directory under the root directory. About 80% of this project has been written in classic asp and 20% has been written in ASP.NET. The login page is written in classic asp so when it creates classic asp session I also create asp.net session so that when a user access asp.net page, the session for asp.net will...
7
1542
by: Thomas Nielsen [AM Production A/S] | last post by:
Hi, I have one web form (WebForm1.aspx) from which i would like to display the output of another web form, WebForm2.aspx, in a controlled environment. I do this by using HttpWebRequest to request WebForm2 from the WebForm1 code-behind, and this works flawlessly. I would also like to be able to share the Session objects between the two webforms. I'm trying to do this by passing the ASP.NET_SessionId cookie on WebForm1 to WebForm2. This...
5
3119
by: bnashenas1984 | last post by:
Hi I'm using IIS on windows XP SP2 just for designing my website. Everything is working fine except session_destroy. When I destroy the session with php nothing happends and session is still available but when I upload the script on my website it works. I think there must be something wrong with my configuration. Doe's anyone know what the exact reason is? Thanks
2
1806
by: ktrw25 | last post by:
I need to find a way when a user closes the browser (not a refresh), to make a log entry into a txt file of the date/time logged out. I have a logout function, but it only works if they hit the log out button. I need to be able to run some code to see if a session is destroyed on the server to make a log entry. Users will be frequently logging in/out & I need to record each entry, so a cronjob will not work. I have not found a way in javascript...
3
13948
by: T. Wintershoven | last post by:
Hi all, After a visitor has loged in, a session is started. The session is destroyed after the visitor clicked "Log out'. When the visitor forgets to log out and closes the browser immediately, the session stil exists because when the visitor opens the browser again and comes back to the site he/she is still loged in. Ofcourse i don't want that. I want the session to be destroyed when the visitor closes the browser
1
2043
oranoos3000
by: oranoos3000 | last post by:
hi I 'd like to session destroy when that user for 1 hours dont dont press any key or scroll page and dont go to another or in other words stay in one page for a alot of time thanks alot
1
3086
oranoos3000
by: oranoos3000 | last post by:
hi i'd like to destroy sessions for logging out logged in user with onuload event from brower i wrote a script that with onunload event brower a function is ran that is writen with jquery and inside this function i send a request for a php file that only destroy session but unfortunately my user is'nt logged out information logged in users that is saved in database is consist of username , ip address thanks alot sepideh mohseni
0
9796
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11153
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10420
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9583
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7134
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6002
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.