简体   繁体   English

iframe仅接受来自特定页面的请求

[英]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. 例如,在页面“ script.php”中,我将添加如下所示的iframe,并通过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. 问题是,用户只需将"process.php?pid=587"直接放在地址栏中即可获得process.php返回的值。 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. 我想对此进行限制,以便仅在“ script.php”请求时才返回该值,否则它将不返回任何内容,或显示错误。

Is it possible to do restriction in such way in php? 是否有可能在php中以这种方式进行限制? If yes, please suggest an way. 如果是,请提出一种方法。

You could try $_SERVER['HTTP_REFERER'] but that depends on the server. 您可以尝试$_SERVER['HTTP_REFERER']但这取决于服务器。

You could put something like this at the top of your process.php : 您可以将以下内容放在process.php的顶部:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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