|
-
Jun 16th, 2008, 03:15 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Prevent Window from Closing
Hi!
How can I, from PHP, prevent a window to be closed? I mean, if certain condition is met (a cookie exists for instance) write some javascript or whatever to prevent the browser to be closed before some action is executed...
Code:
If(cookie)
do not allow window to be closed because session details gotta be saved to a DB before that;
else
Go ahead, close it!;
The biggest man you ever did see was once just a baby.
Bob Marley
-
Jun 16th, 2008, 03:22 PM
#2
Hyperactive Member
Re: Prevent Window from Closing
As far as I can see, you answered your own question.. Or do you want an implementation example?
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Jun 16th, 2008, 03:47 PM
#3
Re: Prevent Window from Closing
IMO it's a waste of time. Trying to prevent the window closing is just going to annoy users.
Aside from that, even if you are successful using Javascript, some users may be using a browser that does not support Javascript, or they may simply have it disabled. They may even have cookies disabled or blocked for untrusted websites.
I suggest you just use some sort og Logout button, which can direct to a page that executes your set cookie code.
-
Jun 16th, 2008, 03:53 PM
#4
Thread Starter
Addicted Member
Re: Prevent Window from Closing
 Originally Posted by the182guy
IMO it's a waste of time. Trying to prevent the window closing is just going to annoy users.
Aside from that, even if you are successful using Javascript, some users may be using a browser that does not support Javascript, or they may simply have it disabled. They may even have cookies disabled or blocked for untrusted websites.
I suggest you just use some sort og Logout button, which can direct to a page that executes your set cookie code.
The disabling of javascript or cookies is not an issue. I got that covered. My users often careless about buttons, so i'm losing log data everytime they don't use the 'logout' button.
Some working code would be of great help
The biggest man you ever did see was once just a baby.
Bob Marley
-
Jun 16th, 2008, 03:55 PM
#5
Hyperactive Member
Re: Prevent Window from Closing
Should you care to explain your *actual* issue further, we may be able to assist you in finding a more suited solution.
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Jun 16th, 2008, 04:04 PM
#6
Thread Starter
Addicted Member
Re: Prevent Window from Closing
Thanks for answering. Everytime a user log into the system, I record to a DB user, date log in, time log in, date log out and time logout. As you may know by now, when they log in I can record the data, but if they just decide to close the browser ignoring the "log Out" button, date logout and time logout won't be recorded.
The biggest man you ever did see was once just a baby.
Bob Marley
-
Jun 16th, 2008, 08:08 PM
#7
Re: Prevent Window from Closing
You can derive the logout time as (last action time + session time-to-live). TTL is arbitrary; usually defined as 15 minutes or thereabouts.
-
Jun 17th, 2008, 07:26 AM
#8
Thread Starter
Addicted Member
Re: Prevent Window from Closing
Thaks for the response penagate. Would you please give me an example of what you're talking about
The biggest man you ever did see was once just a baby.
Bob Marley
-
Jun 17th, 2008, 08:49 PM
#9
Re: Prevent Window from Closing
Well, if you record every authenticated page request in a database along with a timestamp, then you shouldn't need an automatic log out facility.
Add this to every public page:
PHP Code:
require 'includes/log.php';
log.php:
PHP Code:
<?php # some code to prevent this file from being requested directly # ...
sql( 'INSERT INTO accesslog (userid, pageuri) VALUES (?,?)', $userid, $_SERVER['REQUEST_URI'] ); ?>
Something like that. Vary according to taste.
-
Jun 18th, 2008, 09:36 AM
#10
Thread Starter
Addicted Member
Re: Prevent Window from Closing
The biggest man you ever did see was once just a baby.
Bob Marley
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|