title: How to allow my PHP file only load in an Iframe
body: <p>I am trying to protect my content from example.php file. Therefore, I need to disallow direct access to this page as well as any iframe point to it without my permission. </p>
  
  <p>I configure a php file called iframe.php loading iframe from example.com. This is how I did:</p>
  
  <p><strong>Code for example.php:</strong></p>
  
  <pre><code>&lt;?php
   session_start();
   if(!isset($_SESSION['iframe']) || !isset($_GET['internal']) || $_SESSION['iframe'] != $_GET['internal'])
  {
      die("This page can be accessed just from within an iframe");
  }
   unset($_SESSION['iframe']);
   ?&gt;
  </code></pre>
  
  <p><strong>Code for iframe.php</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  $_SESSION['iframe'] = md5(time()."random sentence");
  ?&gt;
  &lt;iframe src="example.php?internal=&lt;?php echo $_SESSION['iframe'];?&gt;" width="500" height="100"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>It works well. However, When I click on any link in iframe.php, I will be redirected to other page. After that, I click the Back button in browser and receive the message: "This page can be accessed just from within an iframe".</p>
  
  <p>Could you please help me keep the page working perfectly after getting back?</p>
  
  <p>Thank you for reading.</p>