How to clear a PHP session using Jquery/Javascript?

后端 未结 3 491
借酒劲吻你
借酒劲吻你 2021-01-02 13:32

Just want to ask if is it possible to clear a PHP session using a jquery or javascript process? Because what I want to do is to clear the PHP session using a dialog box. If

3条回答
  •  抹茶落季
    2021-01-02 14:24

    You can't clear a php session using Javascript directly.

    PHP is a server-side language, whereas Javascript is client-side..

    However, you can throw an ajax request to the specified page that handles the destruction.

    Like this:

    // Client-side
    $.post("logout.php", {"can_logout" : true}, function(data){
    
       if(data.can_logout)
          // redirect the user somewhere
    }, "json");
    
    
     true));
    ?>
    

    Or just point the user to some page that handles the session destruction; i.e. logout.php

提交回复
热议问题