RSS Forums RSS

deleting sessions on closing browser tab

Please support our JavaScript / DHTML / AJAX advertiser: Programming Forums
Reply
Posts: 6
Reputation: vinpkl is an unknown quantity at this point 
Solved Threads: 0
vinpkl vinpkl is offline Offline
Newbie Poster

deleting sessions on closing browser tab

  #1  
Nov 22nd, 2008
hi all

i have my lougout.php which destroys sessions and session ids on logout. I want to have same effect means i want to call this logout.php script when the user closes the "browser tab".

as these are the days of "browser tabs" so this is very important for me.

when the user closed the whole browser then all session and session ids are destroyed automatically but these sessions are not destroying when the user closes the "browser tab".

Its not possible with javascript but its possible with AJAX. I have not used ajax uptil now and have no knowledge. So it would be great if somebody helps me with calling my logout.php script on
closing "browser tab".

this is my logout script

  1. <? require_once("config.php");
  2. $unique_id = session_id();
  3. session_regenerate_id();
  4. $qry="delete from cart_table where unique_id='$unique_id'";
  5. mysql_query($qry);
  6. $_SESSION = array();
  7. session_unset();
  8. session_destroy();
  9. header("Location:index.php");
  10. ?>

vineet
Last edited by vinpkl : Nov 22nd, 2008 at 2:19 am. Reason: left something
AddThis Social Bookmark Button
Reply With Quote  
Posts: 7,398
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 439
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: deleting sessions on closing browser tab

  #2  
Nov 22nd, 2008
There is no reliable/standard way of detecting a browser close event. Though there are non-supported workarounds, a browser close event is not something you should rely on.

Anyways, here is a snippet which seems to be working fine on IE. If you are new to Ajax, I recommend using the AjaxToolbox library to do away with writing most of the boilerplate code.
<!--
    Make async request when a browser window is closed.

    Copyright (C) 2008  sos aka Sanjay

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Script-Content-Type" content="text/javascript">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Example</title>
    <script type="text/javascript" src="AjaxRequest.js"></script>
    <script type="text/javascript">
    // Error checking omitted for brevity
    function doIt() {
      var o = {
        "url": "http://your.domain.net/logout",
        "onSuccess": function(req) {
          alert("status: " + req.status + "\nStatus text: " + req.statusText);
        },
        "onError": function(req) {
          alert('Error!\nStatusText='+req.statusText+'\nContents=' +
              req.responseText);
        }
      };
      AjaxRequest.get(o);
      alert("Request sent; check server logs....");
    }
    window.onunload = doIt;
    </script>
</head>
<body id="bdy">
  <p>Close this window to test forced browser expiry.</p>
</body>
</html>
Last edited by ~s.o.s~ : Nov 22nd, 2008 at 9:14 am.
I don't accept change; I don't deserve to live.

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

-- Eric Naggum RIP :-(
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the JavaScript / DHTML / AJAX Forum
Views: 1694 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:09 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC