【问题标题】:How can I stop html outputting?如何停止 html 输出?
【发布时间】:2022-01-21 01:54:46
【问题描述】:

我正在写一个抗ddos的php脚本,我想写一个自定义加载页面,但是会渲染原始html页面的html页面。无论如何,我是否可以在显示我的 php 加载页面时阻止 html 出现

<?php require "antiddos.php"?>

【问题讨论】:

  • 在 PHP 层防止 DDOS 是徒劳的,在请求管道中为时已晚。执行 PHP 会消耗资源。防止 DDOS 的重点是防止服务器资源被消耗。
  • 我不明白这个问题,例如,如果用户登录的第一页是纯 html,则无法阻止 HTML 在 index.html 中显示。如果是 .php 文件就简单了,使用简单的 if 结构。
  • 是的,当然。为什么不使用die() 来停止执行?

标签: php html output


【解决方案1】:

@Samuel Wang,您可以尝试通过以下示例之一进行检查。 下面假设您包含它的 antiddos.php 和其他文件的代码。

1. antiddos.php:

例如在您的 php 代码之前,或者您可以将 html 保留在不会成为问题的文件中。

 <?php
    
       echo"<p>This is a test html content of antiddos.php</p>";

        function testcall($TextReceiver ){
            return $TextReceiver;
        }
        function MathMultiplication($Prt1,$Prt2){
            return $Prt1*$Prt2;
        }
    ?>

2。 testprocess.php:

你可以使用 ob_clean();包含文件语句旁边的函数,它将丢弃来自 antiddos.php 的内容/html 输出。

<?php require_once("antiddos.php");ob_clean();


echo testcall("Hello this is print call from testprocess.php to antiddos.php");
echo "<br>"; 
echo "MathMultiplication= ". MathMultiplication(4,3);    

?>

两个文件输出的结论:第一个来自antiddos.php,第二个来自testprocess.php

【讨论】:

  • 这是一个很好的答案,谢谢!
猜你喜欢
  • 2017-03-21
  • 2018-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多