简体   繁体   English

如何限制对 PHP 文件的访问,以便只能通过服务器中的 iframe 访问它?

[英]How can I restrict access to a PHP file so that it can only be reached via iframe in my server?

I have a content.php file on my server that I need to load in an iframe on another page mask.php .我的服务器上有一个content.php文件,我需要将它加载到另一个页面mask.php的 iframe 中。 This works just fine but I do not want content.php to be reachable at mydomain.com/content.php, only at mydomain.com/mask.php via iframe.这工作得很好,但我不希望通过 iframe 在 mydomain.com/content.php 上访问content.php ,只能在 mydomain.com/mask.php 上访问。

Is there a way to restrict the access to content.php to only via iframe on same server?有没有办法限制对content.php的访问只能通过同一服务器上的 iframe? PHP or HTTP? PHP 还是 HTTP?

I read about restricting the referrer of content.php , so that it has to be mask.php for it to load but it doesn't seam to work.我阅读了关于限制content.php的引用,因此它必须是mask.php才能加载,但它无法正常工作。 I can imagine that it should be doable with PHP.我可以想象它应该可以用 PHP 实现。

mask.php掩码.php

<?php
if($_SERVER['REQUEST_URI']==='/mask.php' && $_SERVER['SCRIPT_NAME']==='/mask.php')
{
include("content.php");
}
?>

content.php内容.php

<?php

if($_SERVER['REQUEST_URI']==='/content.php' && $_SERVER['SCRIPT_NAME']==='/content.php')
{
die('No Access');
}
elseif($_SERVER['REQUEST_URI']==='/mask.php' && $_SERVER['SCRIPT_NAME']==='/mask.php')

{

echo 'hello';

}

?>

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

相关问题 如何将对服务器上的php文件的访问限制为仅Java应用程序? - How can I restrict access to the php file on server to Java app only? 如何限制对文件的访问,以便只有所有者可以访问? - How to restrict access to file so only owner can access? 如何限制仅从我网站内的页面访问某些PHP页面? - How can I restrict access to some PHP pages only from pages within my website? 如何限制对PHP源代码的访问? - How can I restrict the access to my PHP source code? 如何限制对目录的访问,以便我可以从浏览器运行php脚本 - how to restrict access to directory so I can run php scripts from browser 如何通过php标头访问我的其他服务器上存储的文件? - How can i have access to stored files on my different server via php header? 我怎样才能让多个用户可以访问他们当前的时区,而不是我的服务器使用 PHP 提供的时区 - How can I do so that multiple users can access their current timezone instead of the one provided by my server using PHP 如何通过 Unity 访问服务器上的 PHP 文件以进行 MySQL 数据库操作? - How can I access a PHP file on a server via Unity for MySQL- database manipulation? 设置php文件权限,以便仅我的服务器的curl可以运行 - Set php file permissions so only my server's curl can run PHP-如何限制对页面的访问? - PHP- How can I restrict access to a page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM