Jul 6, 2008

When The Browser Is Closed

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

When The Browser Is Closed

fsoftball
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

Reply

Spectre
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.

Reply

sobhan
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 dry.gif

 

 

 


Reply

no9t9
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.


Reply

dul
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. onclose javascript - 40.78 hr back.
  2. javascript onclose example - 52.88 hr back.
  3. js onclose event ie - 73.72 hr back.
  4. php detect when a user leaves a website - 93.12 hr back.
  5. browser onclose - 93.52 hr back.
  6. javascript onclose() - 90.52 hr back.
  7. javascript onclose - 0.77 hr back.
Similar Topics

Keywords : browser, closed

  1. Php Source Code Unveiled In Browser?
    is that possible? (7)
  2. Need Some Help In File Browser
    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
    places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders
    and list them in simply. ) Also, it creates a directory (any name) inside each sub folder. My
    Following code reads on the files inside the main directory, it does not read the files inside the
    sub-folders.. I appreciate any help. CODE <? $path = "./"; $dir_handle =
    @opendir($path) or die("Unable to open $path"); whil....
  3. Browser Problems, Maybe?
    Firefox vs IE (6)
    Alright, I coded something the other day for the game I am working on making, and a few of my
    friends I allowed to get on it and test things out. Well....the ones that were on IE their
    characters were made but the User variable as in which account they were on just stayed blank, while
    with my friends that were on Firefox, everything worked fine and they could play perfectly... So I
    was wondering, with PHP sql codes being sent to the database, is there something special you have to
    do to make it work on both, or could it be a setting on the IE that was messing with it......
  4. 2d Traveling On Browser
    PHP Game (4)
    Alright I am developing a PHP Game. I have worked on one but left them due to creative differences.
    Something that I have had trouble finding in script tutorials and script archieves is a way to do
    like a 2d mini world inside of the game. Like let's say that you have a icon for your person, it
    would put it on the map where you are at in the game and it moves as you go to different places in
    the world. something like this(horrible cause done with X's and | _): _______________________
    |_|_|_|_|_|_|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|_|_|_|_|_|_| |X|_|_|_|_|_|_|_|_|_|_|....

    1. Looking for browser, closed

Searching Video's for browser, closed
advertisement



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