[英]Distroying session in php set by jQuery?
我該如何銷毀由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>
您想銷毀會話的位置包括以下代碼
說這是在session_destroy.php文件中
<?php
session_start();
session_destroy();//OR use unset if u want to destroy individual session.
clearstatcache();
?>
並在您需要的任何情況下對此文件進行ajax調用。
對於ajax電話
jQuery("#psubmit").mousedown(function(){
hasBeenClicked = 1;
//AJAX call
$.ajax({
url: 'session_destroy.php',
type: 'POST',
dataType: "json",
data: {
},
success: function(data){
}
});
////AJAX call
});
會話在服務器上維護,如果不向服務器發送請求,則無法在客戶端上刪除會話。 因此,您應該為后一種形式提供另一個api,以破壞會話服務器端,就像設置會話服務器端一樣。
您需要像這樣破壞jQuery帖子上的會話:
$('#hello').click(function() {
$.post("destroy.php", function(){
location.reload();
});
});
然后在destroy.php中
sessionstart();
sessiondestroy();
如果您在表單上使用它,則必須確保阻止默認表單提交,如果您希望它在不重新加載的情況下進行ajax調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.