Sessions DO NOT end when a user closes their browser. There is no communication with the server when a browser is closed so there is no way the server can know to end the session. The same is true when you leave the site for another. Again no communication takes place between your browser and the site you're leaving so the server never knows you've left.

Basically the only solution I know of is to set up a client-side event to call a server-side script to abandon the session when the user leaves.

Anyone knows how to write a javascript to end a session when the browser is being closed?

Sessions are controlled by the web server... you can't terminate them with JavaScript code. Usually, sessions are set to time-out in 15 minutes (I think that's IIS' default, different web servers may vary).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.