title: How to save current url ID to a session and then update it upon viewing the next submission
body: <p>Upon refreshing <a href="http://mydomain.com" rel="nofollow">http://mydomain.com</a>, it will generate a random ID to display on the page.</p>
  
  <p>For example, <a href="http://mydomain.com" rel="nofollow">http://mydomain.com</a> generates 54 the first time, and upon reloading, 112, etc.</p>
  
  <p>I'd like to save each of the randomly generated IDs to a session, so each time it reloads, I can go back to the last one. For example, the first time it saves 54 to a session, and when <a href="http://mydomain.com" rel="nofollow">http://mydomain.com</a> reloads and generates 112, I can link back to the 54.</p>
  
  <p>I can't use HTTP_REFERER or REQUEST_URI, so I tried to work on my own version, but it's only saving it once. I can't figure out how to update it upon viewing the next ID.</p>
  
  <pre><code>    if(empty($_SESSION['lastURL'])) {
          $_SESSION['lastURL'] = $submissionId; // $submissionId is randomly generated
              } else {
          echo $_SESSION['lastURL'];
      }
  </code></pre>
  
  <p>Is my current code. Where should I update the session to store the next ID?</p>
  
  <p>Turns out the reason it kept misfiring was because it kept firing an additional ajax request, so I was getting a randomly generated id each time.</p>
  
  <p><strong>I (with the help of a friend) figured out by using the following code, and setting it before it randomly fires each time:</strong></p>
  
  <pre><code>    if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest'){
      // Not an ajax request - just a normal page load
      $_SESSION['lastid'] = $_SESSION['currentid'];
      $_SESSION['currentid'] = $submissionId;
  }
  </code></pre>