New Coder Posted January 24, 2008 Share Posted January 24, 2008 Hi all, I was wondering if it was possible to change a value within a DB if a user closes their browser via the bowsers close crosses or menu-file-exit? example: I have a DB table with users details and a column called edit which is defaulted to "N". A "Master user" selects an individual or a group of "standard users" from a list which then sets the standard users edit field to "Y". This will then allow these standard users to access other parts of the site, edit profiles etc. Now, I can obviously create a button on a page that will reset "Y's" to "N's" removing editting rights. But if the "Master user" forgets to use the reset edit button, closes browser and goes home they will leave people with editing rights etc. Is there a way round this? Many Thanks p.s i hope my example makes sense... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 24, 2008 Share Posted January 24, 2008 I would use a cron job that ran every once in a while. It would open a php file, and connect to the database and change the proper Y's to N's This file would have to be placed outside the root directory of your web site so it can not be accessed from the web a.k.a. a browser. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 PHP is not like Visual Basic where you can do something like on a close event. It's a server side script that delivers a page. Maybe JS can do it, but PHP can't. Hi all, I was wondering if it was possible to change a value within a DB if a user closes their browser via the bowsers close crosses or menu-file-exit? Quote Link to comment Share on other sites More sharing options...
jorgep Posted January 24, 2008 Share Posted January 24, 2008 I'm not sure about this, but see if there is any javascript that detects when a window is close. If you can detect that, you can use ajax or something similar to make your db changes. Let me know! Quote Link to comment Share on other sites More sharing options...
jorgep Posted January 24, 2008 Share Posted January 24, 2008 I just tried this, and at least I'm getting the alert message. Try making an Ajax call instead of the alert and let me know <html> <head> <script type="text/javascript" language="javascript"> function triger_acction(){ alert('Browser is being closed!'); } </script> </head> <body onunload="triger_acction()"> Hello! </body> Quote Link to comment Share on other sites More sharing options...
New Coder Posted January 24, 2008 Author Share Posted January 24, 2008 Thanks people, Working with your example jorgep I have managed to stop them from closing the window (in a round about way) by forcing it to open a new window. <html> <head> <Script Language="JavaScript"> function triger_action() { var load = window.open('http://www.website.com'); } </script> </head> <body onunload="triger_action()"> Hello! </body> So I could make it open a page that says you have not removed editing rights click he to remove and so on. Quote Link to comment Share on other sites More sharing options...
New Coder Posted January 24, 2008 Author Share Posted January 24, 2008 With a combination of things I now have: <html> <head> <Script Language="JavaScript"> function triger_action() { var where_to= confirm("Have you removed editing"); if (where_to== true) { window.close(); } else { var load = window.open('http//:www.website.com'); } } </script> </head> <body onunload="triger_action()"> Hello! </body> Which kinda works. It would be a wierd situation if you sent them to another site with this code as they would never be able to close browser... Quote Link to comment Share on other sites More sharing options...
jorgep Posted January 24, 2008 Share Posted January 24, 2008 Yeah, thats weird hehehe, I've never tried that, that would be sooo annoying! Good thing it worked I would have tried an ajax approach, instead of doing this: if (where_to== true){ window.close(); } else { var load = window.open('http//:www.website.com'); } Quote Link to comment Share on other sites More sharing options...
New Coder Posted January 24, 2008 Author Share Posted January 24, 2008 Never tried/used ajax though..but i will look into it Cheers Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 24, 2008 Share Posted January 24, 2008 http://phpsnips.com/snippet.php?id=27 Or http://www.tizag.com/ajaxTutorial/ Quote Link to comment Share on other sites More sharing options...
New Coder Posted January 24, 2008 Author Share Posted January 24, 2008 cool Thanks liitle guy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.