close user from site with clicking close button of browser

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oranoos3000
    New Member
    • Jan 2009
    • 107

    close user from site with clicking close button of browser

    hi
    i,m writing a script for chat room
    i,d like to with clicking close button of browser user is exited from site
    meaning of this say is with clicking close button all of session variable
    is removed from server
    i wrote below code for this action
    but sorry i failed
    please help me
    my base page code is as follows
    Code:
    <?php
    session_start();
    $_SESSION['username']='sima';
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function getData(source)
    {<!--119-->
    	var XMLHttpRequestObj=false;
    	if(window.XMLHttpRequest)
    	{	XMLHttpRequestObj=new XMLHttpRequest();}
    	else if(window.ActiveXObject)
    	{	XMLHttpRequestObj=new ActiveXObject("Microsof.XMLHTTP");}
    	
    	if(XMLHttpRequestObj)
    	{<!--131-->
    		XMLHttpRequestObj.open("GET",source);
    		XMLHttpRequestObj.onreadystatechange=function()
    		{<!--135-->
    			if(XMLHttpRequestObj.readyState==4 && (XMLHttpRequestObj.status==200 || XMLHttpRequestObj.status==0))
    			{<!--137-->
    			newWindow=window.open("show_users.php","new users");
    			newWindow.focus();
    			}<!--e137-->
    		}<!--e135-->
        }<!--e131-->
    		XMLHttpRequestObj.send(null);
    }<!--e119-->
    
    </script>
    </head>
    
    <body onUnload="getData('exit.php');">
    
    </body>
    </html>
    code of exit.php is as follows
    Code:
    <?php
    session_start();
    session_destroy();
    ?>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    have you tried window.onbefore unload?

    Comment

    Working...