A page should be opened only in a window
<p>I have a small application in PHP in which when a button (<code>type='button'</code> and not <code>type='submit'</code>) is clicked, a new window is opened and a page is loaded into that window. Some insertion operations into the database are performed on that page on the window using Ajax.</p>

<p>The page which is loaded into the window should only be opened in a window. If the URL of that page is entered directly into the address bar of the web browser, the page must be protected and redirected to some other page, it may be a home page of the application. I tried using <code>window.opener.closed</code> but it doesn't suit this requirement.</p>

<p>In PHP, I can check </p>

<pre><code>if($_SERVER['REQUEST_METHOD'] == "GET")
{
    header("location:Home.php");
}
</code></pre>

<p>But that will also redirect the page in the window to the Home.php page because I'm using Ajax on the <code>GET</code> request on that page.</p>

<p>Is there a way to determine if a page can only be loaded into a window? In all cases, it must be prevented from being loaded.</p>

<p>Thanks.</p>
