【问题标题】:Stop Php Execute in page [duplicate]在页面中停止Php执行[重复]
【发布时间】:2021-02-15 17:35:23
【问题描述】:

我已在 My Domain2 中添加了此代码,我希望在其中执行此代码,如果它来自域 1 则运行

 <?php if(isset($_GET['id2'])) { $id2=$_GET['id2']; echo "www.xxxxxxxxxx"" ></iframe>";}
                                                    else
{
echo "Not Found";

}

我尝试了这段代码,但没有工作 如果有人直接访问此https://Domain2.com/xxxxxxxx/?id=xxxx 隐藏部分正在显示 不被https://Domain1.com/away.php重定向时如何隐藏

【问题讨论】:

  • 您可以检查$_SERVER['HTTP_REFERER'],但不保证设置或准确,然后exit。
  • 您想检查它是否使用id 或其他方式从域1 重定向?

标签: php


【解决方案1】:

您可以使用 $_SERVER['HTTP_REFERER'] 确保引用页面(上一页)是您期望的页面:

<?php 
// if the request comes from a file that contains the string "conforming.php" then render the page
    if(stristr($_SERVER['HTTP_REFERER'], "conforming.php")) {
         //serve page if came from conforming.php
     }
// if the referring page is not conforming.php, then redirect the user to the conforming version
    else  {
        header("Location: conforming.php");
    }
?>

其他信息:https://www.w3.org/TR/WCAG20-TECHS/SVR3.html

编辑** 我根据您的附加要求定制了以下代码:

<?php 

if (stristr($_SERVER['HTTP_REFERER'], "https://Domain1.com/away.php"))
{
    if (isset($_GET['id2']))
    {
        $id2 = $_GET['id2'];
        echo "<iframe frameborder=\"0\" scrolling=\"no\" width=\"560\" height=\"320\" src=\"https://www.xxxxxxxxxx.com/files.php?v=$id2\" allowfullscreen=\"true\" webkitallowfullscreen=\"true\" mozallowfullscreen=\"true\" ></iframe>";
    } else{
        echo "id is empty";
    }
    
}
else
{
    //invalid referer! go back to domain1 to make it valid!
    header("Location: https://Domain2.com/xxxxxxxx/");
}

?>

【讨论】:

  • 我试试这个直接执行的url xxxxxx.com/files.php?v=$id2\" allowfullscreen=\"true\" webkitallowfullscreen= \"true\" mozallowfullscreen=\"true\" >";} else { echo "Stop"; } if(stristr($_SERVER['HTTP_REFERER'], "xxxxxxxxx.com/away.php")) { //如果页面来自conforming.php } else { header("Location: xxxxxxxxx"); } ?>
  • 您可以在处理 iframe 之前先检查 $_SERVER['HTTP_REFERER']。
  • 感谢您帮助我。我编辑了问题,请您检查并修复我的代码
  • 很高兴听到这个消息!
  • 请注意,引用引用值很容易被欺骗,因此它只能提供非常低的安全性
【解决方案2】:

你要找的是退出;

<?php 

if(isset($_GET['id'])) 
{ 
  $id1=$_GET['id']; echo "xxxxxxxxxx=$id1";}
else {
  echo "stop";
  exit;
}

?>

Exit 将终止当前脚本的执行。然后这将继续执行过程,这将调用您的下一个函数。

更多阅读:https://www.php.net/manual/en/function.exit.php

【讨论】:

  • 如果 id= 在 URL 中没有任何内容,则显示停止字
  • 是的,这很完美。它正在做你现在写的。它的回声会停止,然后退出脚本。您的代码运行良好。 id 未设置为您的“else”中的任何内容,并且只有在未设置 id 时才进入那里。
猜你喜欢
  • 1970-01-01
  • 2011-05-13
  • 1970-01-01
  • 2011-03-19
  • 1970-01-01
  • 2017-10-28
  • 2018-11-01
  • 2013-09-28
相关资源
最近更新 更多