2014-06-30 118 views
0

如何銷燬由jquery設置的php會話。在jQuery中破壞php中的會話?

代碼註冊會話:

$('#psubmit').click(function() { 

    $.post("single-us_portfolio.php", {"myusername": "myusername"});  

}); 

,並就custom.php代碼訪問會話:

session_start(); 
$_SESSION["myusername"] = $_POST["myusername"]; 
if(!session_is_registered(myusername)){ 

echo '<meta http-equiv="Refresh" content="1; url=http://www.ididthisfilm.com/lex_tmp2/the-lexicon/">'; 
} 

現在,我想在這個表單提交破壞這個會議:

<form > 
<input type="file" class="js-file-validation-image" name="file" id="filed" required="required"> 
<input type="submit" value="PUBLISH PHOTO" id="hello" name="publishpost" > 
</form> 
+0

當你想破壞會議?在哪個事件? –

+0

點擊提交按鈕,ID爲「hello」 – user3739733

+0

您可以在需要時使用'session_destroy'功能。 – Saqueib

回答

0

會話在服務器上維護,無法在客戶端上刪除而不發送請求者st到服務器。所以你應該爲後一種形式提供另一個API來銷燬會話服務器端,就像設置會話服務器端一樣。

1

你在哪裏都想要摧毀會話包括下面的代碼

說這是session_destroy.php文件

<?php 
session_start(); 
session_destroy();//OR use unset if u want to destroy individual session. 
clearstatcache(); 
?> 

並給予Ajax調用這個文件,U上想要的任何事件。

對於Ajax調用

jQuery("#psubmit").mousedown(function(){ 

hasBeenClicked = 1;        
//AJAX call 
    $.ajax({ 
     url: 'session_destroy.php', 
     type: 'POST', 
     dataType: "json", 
     data: { 

     }, 
     success: function(data){         

     } 
    }); 
////AJAX call 

    }); 
+0

如何? ajax調用這個文件?請 – user3739733

+0

這是如何ü給ajax電話銷燬會話 –

+0

@ user3739733,我更新了答案。它解決你的第二個問題 –

0

你需要摧毀的會議jQuery的崗位像這樣:

$('#hello').click(function() { 

    $.post("destroy.php", function(){ 
     location.reload(); 
    }); 
}); 
在destroy.php

sessionstart(); 
sessiondestroy(); 

然後如果你正在使用它在一個表單上,你必須確保你已經阻止了默認的表單提交,如果你想讓它成爲ajax ca沒有重新加載。