I'm doing a simple chat script and I have the killSession function which kills the current session and deletes the user from the DB. The problem is that after the name is set and verified the chat form doesn't load, it just kills the session and goes back to the loginForm(). Here's the script:
<?php
if (!isset($_SESSION['name'])) {
loginForm(); // set a name for chat
} else {
?>
// chat form
$(window).unload(function () {
<?php killSession(); ?>
});
Is there a way to trigger killSession() only after I refresh or close the page?
UPDATE:
Still can't figure it out. Maybe I need a break.
$(window).unload(function () {
$.get("killSession.php", { name:"test" }); // i set the name to test for testing
});
Here's the killSession.php page:
session_start();
function killSession($name) {
include("config.php");
mysql_query("DELETE FROM sessions WHERE name='$name'");
session_destroy();
header("Location: index.php");
}
killSession($_GET['name']);
The $.get still doesn't work, so I tried it separatly via the browser. killSession.php?name=test will delete from the DB, but won't kill the session.