title: PHP HTTP_REFERRER - how to detect last page?
body: <p>I need to detect where the user has just clicked from - as my AJAX content needs to be displayed differently depending on the source page it is to be inserted into. </p>
  
  <p>If it's to go into about.php it needs to be data only, but if it's to go into about-main.php it needs to be the whole middle column so needs a header/footer wrapper around the data.</p>
  
  <p>The html called via AJAX is held in a php page which uses this code to see who's asking, and then formats the HTML response appropriately.</p>
  
  <pre><code>$array[] = "/cf/about.php";
  $array[] = "/cf/about/about-main.php";
  $array[] = "/cf/about/other-page.php";
  
  
  $ispage = "";
  foreach ($array as $value) {
      if ($_SERVER['HTTP_REFERER'] != $value) {
          $ispage = "";
      } else {
          $ispage = "woot";
      }
  }
  if ($ispage == "woot") {
          echo $content;
      } else {
          include_once 'about-header.php';
          echo $content;  
          include_once 'about-footer.php';
  }
  </code></pre>
  
  <p>The problem is... HTTP_REFERER seems to be a bit hit and miss. It works just fine while I'm at work on the network, but I've tried it out on my computer at home and it's obviously completely failing to work - the results are horrible :o</p>
  
  <p>Is there another way of achieving this? I guess session variables could be used but then I've not got much experience of that!</p>
  
  <p>Any and all hints/tips are appreciated ;)
  Thanks!</p>
  
  <p>edit:</p>
  
  <p>The page is actually a staff profile page. Its normal location is about.php and the 2nd column div displays a grid of thumbnails which when clicked, load the profile in that place via AJAX. All nice and simple - back button reloads the grid of photos.</p>
  
  <p>The problem is, each staff member also needs a static page. I've created these at about/staff-name.php. The content is THE SAME though. I want the server to detect if someone has come to the about/staff-name.php directly and if so, wrap a header/footer around it.</p>
  
  <p>If the request has come from the grid of photos (ie AJAX) then it doesn't need the header/footer wrapper.</p>
  
  <p>Is that clear? :o</p>
  
  <p>1) If AJAX request - no wrapper
  2) If not AJAX request - add header/footer wrapper</p>