How to unset session when leaving website but not when refresh?

472 Views Asked by At

I need to have my web app destroy/unset the Zend_Auth session when a user leaves the site: for example when a user navigates away from myapp.com to say google.com, when they come back the session is no longer set?

Preferable to allow refresh without unsetting (but not essential as the first part must apply).

Anyone had experience with doing this before?

1

There are 1 best solutions below

3
omars On BEST ANSWER

Make an ajax call before unloading the page, that clears the identity of the Zend Auth

<script language="JavaScript">
        window.onbeforeunload = function(){
        $.get('http://example.com/auth/clear');
    }
</script>

ServerSide:

public function clearAction(){
    Zend_Auth::getInstance()->clearIdentity();
}