我需要運行該代碼:運行PHP代碼接近使用Javascript
<?PHP
$pin=$_GET["pin"];
unlink("../users/$pin/host.php");
unlink("../users/$pin/votes.php");
unlink("../users/$pin/guest.php");
rmdir("../users/$pin");
echo "Session ended";
?>
它位於php/endsesh.php
基本上,當你啓動一個會話它創建你有一個文件夾PIN號碼,它放置一個主機,來賓和投票文件。
我需要這個PHP腳本時,標籤被關閉運行,因此它可以刪除所有這些文件(否則,我只是在我的超載與文件服務器)
到目前爲止我沒有運氣嘗試這種:
<script>
window.onbeforeunload = function() {
alert("<?php include("http://musicdemo.hol.es/php/endsesh.php?pin=" . $_GET["pin"]; ?>");
$.get("http://musicdemo.hol.es/php/endsesh.php?pin=<?php echo $_GET["pin"]; ?>");
return false;
return "If you exit this page your session will not end. Please either allow the pop-up, by staying in this page and closing again, or click the link saying 'Close this session'";
}
</script>
既不alert
或$.get
命令的工作。
所以,基本上,你需要執行endsesh。當用戶關閉標籤的PHP? –
注意:javascript無法執行php – Isaac
@Isaac這是不正確的。 JS可以加載一個PHP頁面,這將導致服務器執行PHP代碼。 – krowe