| | |
deleting sessions on closing browser tab
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2008
Posts: 6
Reputation:
Solved Threads: 0
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
vineet
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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<? require_once("config.php"); $unique_id = session_id(); session_regenerate_id(); $qry="delete from cart_table where unique_id='$unique_id'"; mysql_query($qry); $_SESSION = array(); session_unset(); session_destroy(); header("Location:index.php"); ?>
vineet
Last edited by vinpkl; Nov 22nd, 2008 at 3:19 am. Reason: left something
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.
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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- 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 10:14 am.
I don't accept change; I don't deserve to live.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: javascript form help
- Next Thread: Regarding add new row in the Table.
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug captchaformproblem checkbox close codes createrange() css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsp jump listbox maps masterpage math media menu microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal pdf php player position problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select software sql text textarea unicode w3c window windowofwords windowsxp \n






