javascript - Logout and Delete Cookies [Redirect to main page] -


when user clicks logout button main page, cookies deleted , redirected window.location = url; . if user not login, instead clicks logout, still redirected window.location = url;. codes below, can't seem logout if click logout button , stay @ main page while being logged in. can tell wrong? new javascript , need regarding topic.

$('.logout-btn').click(function(e){   e.preventdefault();    if(isset($_cookie['referer']) && $_cookie['referer'] != '') {     window.location = url;   }   else {     $.post(outurl, function( data ) {     }).then(function(r){       $('#popup_ok, .x-close').bind( "click", function() {         window.location = url;       });       if(r.result == 1){         popup_msg('failed', r.msg);       }       else{         popup_msg('success', r.msg);         settimeout(function(){           window.location = url;         },2000);       }     });   } }); 

try code execute when user close tab or close browser automatically destroy session , cookies stored

<body onbeforeunload='destroysession()'> </body>   <script type='text/javascript'> function destroysession() {     $.ajax({        url: 'process/logout.php'  });  }  </script> 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -