I have a small application in PHP in which when a button (type='button' and not type='submit') 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.
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 window.opener.closed but it doesn’t suit this requirement.
In PHP, I can check
if($_SERVER['REQUEST_METHOD'] == "GET")
{
header("location:Home.php");
}
But that will also redirect the page in the window to the Home.php page because I’m using Ajax on the GET request on that page.
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.
Thanks.
Did you check if the opener attribute was set if you opened that protected adress in a regular browser adress bar? If not then you could check it on loading the window, and exit whenever this value is unset