简体   繁体   中英

Iframe accept request only from a certain page

I want to create a page that will accept request only from a particular page in my server.

For example, in page "script.php", I am adding an iframe like follows, and sending a variable via url.

<iframe src="process.php?pid=587"></iframe>

The problem is, users can get the value returned by process.php simply by putting "process.php?pid=587" at the address bar directly. I want to restrict this so that the value will only be returned if requested by "script.php", otherwise, it will return nothing, or show error.

Is it possible to do restriction in such way in php? If yes, please suggest an way.

You could try $_SERVER['HTTP_REFERER'] but that depends on the server.

You could put something like this at the top of your process.php :

if ($_SERVER['HTTP_REFERER'] != 'script.php') {
    die;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM