You can attach an unload event to the window.
In the function called from this event you can run a synchronous (this
is imperative) ajax request to a server-side script which kills the session.
$(window).unload(function(event){
$.ajax(
{
async: false,url: "/some-url-to-script-that-kills-session/",
cache: false
}
);
});
Looks like you are mixing javascript and PHP.. Remember PHP is running on
the server side, and any action you perform in the PHP will be performed
when the request to the server is made.
PHP serves the content to the browser.
Hope this helps.
My 2 cents, why would you want to destroy the session when the page reloads?
Wouldn't this be annoying for users?
Cam
On Mon, Aug 24, 2009 at 4:17 AM, Norbert <[email protected]> wrote:
>
> I'm doing a simple chat script and I have the killSession function
> which kills the current session and deletes the user from the DB. The
> problem is that after the name is set and verified the chat form
> doesn't load, it just kills the session and goes back to the loginForm
> (). Here's the script:
>
> <?php
> if(!isset($_SESSION['name'])){
> loginForm(); // set a name for chat
> } else {
> ?>
> // chat form
>
> $(window).unload( function () {
> <?php killSession(); ?>
> });
>
> Is there a way to trigger killSession() only after I refresh or close
> the page?
>