title: Set a session variable when a link is clicked
body: <p>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:</p>
  
  <pre><code>$(window).load(function () {
      $("#hdr li a").click(function () {
          $.ajax({
              type: "POST",
              url: "clear.php",
              data: "width=0"
          });
      });
  });
  </code></pre>
  
  <p>(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.)</p>
  
  <p>and in the file 'clear.php' I simply have:</p>
  
  <pre><code>&lt;?php session_start();
  
  $_SESSION['name'] = 0;
  
  ?&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>This works in some browsers (Firefox and Chrome) but not in others (e.g., Safari).</p>
  
  <p>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.</p>