I want to set a session variable to 0 when any of a certain set of links are clicked. To do this I have put the following in my javascript file:
$(window).load(function () {
$("#hdr li a").click(function () {
$.ajax({
type: "POST",
url: "clear.php",
data: "width=0"
});
});
});
(Ignore data: "width=0"... I don't use this data in clear.php. I put it there because I thought maybe I had to specify a data field.)
and in the file 'clear.php' I simply have:
<?php session_start();
$_SESSION['name'] = 0;
?>
So, the idea is that when any of the links in #hdr li are clicked, the user should be taken to the page that the link points to, via clear.php, which sets the session variable to 0.
This works in some browsers (Firefox and Chrome) but not in others (e.g., Safari).
Is this the standard/correct way to implement what I want? Also, how does the browser know where to go after visiting clear.php? Somehow it works, but my first thought was that I should pass the final destination URL into clear.php, and then use "header" to move from clear.php to the final destination.