I think your asking if there's a way to end a session on a server when the web browser is closed.
By using a cookie that doesn't survive the browser close- the re-opening of the browser won't let you in the session.
However, there's no way to get the browser closing to send out a message to the server to end the session.
Please do your own homework.
I am here to help you, not do it for you.
I do not have sample code for anything