title: PHP: How to detect direct requests of external visitors?
body: <p>I would like to detect/prevent/forward direct requests of external visitors. Some scripts should only be displayed in a jQuery dialog. </p>
  
  <p>My current code:</p>
  
  <pre><code>&lt;script&gt;
  $(".dialog").click(function() {
      // some code for validation
      // ...
      $("#dialog").load(this.href).dialog();
  });
  &lt;/script&gt;    
  
  &lt;a href="http://domain.de/path/to/form/" class="dialog"&gt;Open me in a dialog&lt;/a&gt;
  </code></pre>
  
  <p>That works fine BUT if I open this link in a new tab/window (e.g. by clicking the middle mouse-button), the form will be displayed "naked".</p>
  
  <p>In this case I would like to forward the user to the refered page, e.g.:</p>
  
  <pre><code>if ($requester != $server) {
      header ("Location: " . $_SERVER["HTTP_REFERER"];
  }
  </code></pre>
  
  <p>How can I detect $requester and $server? I don't want to block every script or a whole directory!</p>
  
  <p>Thanks in advance!</p>