| | Hi, I am storing data in a table based on the session id. When the user closes their browser, I want to run a quick delete so that the entery to the db with that session id is removed. How can I do this? Thanks |
|
|
It's not really possible to detect when a user closes their browser window, per se. There are ways to do it - such as raising a window with the JavaScript OnClose() event, but that isn't reliable as not all clients are going to support it, and it could be blocked by anti-popup software and the like, as well as any number of other possible problems.
The way IPB works out which users are online is by tracking their movements with a timestamp of their last page view, and then automatically removing all session data for each user that has been inactive for a certain amount of time. Although it makes it easier that there is a login system, you would be able to use cookies, session data, or the client's IP address to track their movements and remove their session from the database when they don't refresh a page for, say, 20 minutes. Unfortunately, this isn't a 100% surefire way of doing it either, as visitors may share an IP address or block cookies or not support session information being stored, but it is probably your best bet. QUOTE(Spectre @ Sep 27 2005, 05:42 AM) It's not really possible to detect when a user closes their browser window, per se. There are ways to do it - such as raising a window with the JavaScript OnClose() event, but that isn't reliable as not all clients are going to support it, and it could be blocked by anti-popup software and the like, as well as any number of other possible problems. The way IPB works out which users are online is by tracking their movements with a timestamp of their last page view, and then automatically removing all session data for each user that has been inactive for a certain amount of time. Although it makes it easier that there is a login system, you would be able to use cookies, session data, or the client's IP address to track their movements and remove their session from the database when they don't refresh a page for, say, 20 minutes. Unfortunately, this isn't a 100% surefire way of doing it either, as visitors may share an IP address or block cookies or not support session information being stored, but it is probably your best bet. I agree, pop-ups are problem. you can store data in varible, not in database. If you want to delete data after users closes the window, it is easily to store data in varible. You can use arrays too
It is bad programming to store temporary variables in a database. Depending on what you are using the information for, there is a "best practice" solution. Since you are basing your post around the session ID and closing the browser, I am assuming that the information saved in the database is used based on a per visit basis.
In the case where you want to store information for a customer that is deleted after every visit, you should store that information in cookies. When the user leaves you never have to worry about deleting it. In addition, you could track a returning user. On the other hand, if you are just storing information that doesn't get passed to various pages, it may be best to use temporary variables and arrays, passing them through the URL. QUOTE(fsoftball @ Sep 27 2005, 02:18 AM) Hi, I am storing data in a table based on the session id. When the user closes their browser, I want to run a quick delete so that the entery to the db with that session id is removed. How can I do this? Thanks Hi, take a session boolean variable which takes that customer is using your DB and one integer variable which saves browser hadle. If customer accessing to your DB check that handle number. If handle number is different that customer trying to access from other window (I mean, opened another browser), and set that boolean variable false value. after that you can cut the accessing. Use WINAPI function to get browsers handle FINDWINDOW(). Good luck
Recent Queries:-
Keywords : browser, closed
listing all sub folders and files in them. (8) Hey I want to create a very simple file browser, so that, it reads all the sub-folders which are Firefox vs IE (6) Alright, I coded something the other day for the game I am working on making, and a few of my PHP Game (4) Alright I am developing a PHP Game. I have worked on one but left them due to creative differences. Looking for browser, closed
|
|
![]() When The Browser Is Closed |
| ADD REPLY / Got an Opinion! | Remove these ADs! | RAPID SEARCH! | Free Web Hosting | [X] |
|
Express your Opinions, Thoughts or Contribute more info. to help others. Ask your Doubts & Queries to get answers, So that "Together We can help others!" |
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP. | 500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE |
|