phpzend-frameworkzend-sessionzend-session-namespace

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


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?


Solution

  • 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();
    }