title: How can i check if the current window is "top" (or "parent") via php?
body: <p>I need to display a link if the current page is being viewed in parent browser window, or display another link if window is being viewed inside an iframe.
  How can i do that via php? Something like:</p>
  
  <pre><code>if (self == top)
          echo '&lt;span&gt;&lt;a href="./" &gt;Link1&lt;/a&gt;&lt;/span&gt;';
  else
          echo '&lt;span&gt;&lt;a href="./index.php"&gt;Link2&lt;/a&gt;&lt;/span&gt;';
  </code></pre>
  
  <p>edit: since it cant be done with php, i still looking for similar solution, maybe JS, can someone pls tell me how?</p>
  
  <p>Final edit:
  The answer:</p>
  
  <pre><code>echo '  
  &lt;script type="text/javascript"&gt;
      if(window === top) {
  document.write("&lt;span&gt;&lt;a href=\"./\"&gt;go-to-frame&lt;/a&gt;&lt;/span&gt;");
      }
      else {
  document.write("&lt;span&gt;&lt;a href=\"./index.php\"&gt;go-to-top&lt;/a&gt;&lt;/span&gt;");
      }
  &lt;/script&gt;
  ';
  </code></pre>
  
  <p>thank you all.</p>