Php 如何拦截请求,然后加载内容

Php 如何拦截请求,然后加载内容,php,Php,因此,我有以下代码: header('X-Powered-By: Mecanik1337'); header('X-Frame-Options: SAMEORIGIN'); header('X-XSS-Protection: 1; mode=block'); header('X-Content-Type-Options: nosniff'); header("X-Message: Why are you seeing this? Bad boy!");

因此,我有以下代码:

  header('X-Powered-By: Mecanik1337');
    header('X-Frame-Options: SAMEORIGIN');
    header('X-XSS-Protection: 1; mode=block');
    header('X-Content-Type-Options: nosniff'); 
    header("X-Message: Why are you seeing this? Bad boy!");

    if (!isset($_COOKIE['SOMECOOKIE'])){ # not interesting.
        setcookie('SOMECOOKIE', true,  time()+3600); // every hour :)
        echo ' Please wait....'; 

    <br><script>
                var counter = 5;
                var seconds = "";
                setInterval (function()
                {
                counter--;
                if(counter < 1)
                {
                window.location = "index.php";
                }
                else
                {
                if(count <= 1) seconds = " second";
                else seconds = " seconds...";
                document.getElementById("count").innerHTML = counter + seconds;} }, 1000);

                <noscript>
                <h1 style="color:red;">Please turn JavaScript on and reload the page.</h1>
                <noscript>
        die(); # die xD
    }
header('X-Powered-By:mecanik137');
标题('X-Frame-Options:SAMEORIGIN');
标题('X-XSS-Protection:1;模式=块');
标题('X-Content-Type-Options:nosniff');
标题(“X讯息:你为什么看到这个?坏孩子!”);
如果(!isset($_COOKIE['SOMECOOKIE']){{不有趣。
setcookie('SOMECOOKIE',true,time()+3600);//每小时:)
echo‘请稍候……’;

var计数器=5; var秒数=”; setInterval(函数() { 计数器--; 如果(计数器<1) { window.location=“index.php”; } 其他的 {
如果在Javascript代码中有(count)

document.getElementById("count").innerHTML = counter + seconds;
这将定位一个id为“count”的DOM元素(因此“get element by id”)并将所需的文本放在其中

但是元素必须存在,否则document.getElementById将返回NULL,并且您将尝试修改NULL的innerHTML。这是无法完成的

要创建这样的元素,只需输出适当的HTML文档:

setcookie('SOMECOOKIE', true,  time()+3600);
print <<<DOCUMENT
<html>
    <body>
        Please wait <div id="count"></div>
        <noscript>
            <h1 style="color:red;">
                 Please turn JavaScript on and reload the page.
            </h1>
        </noscript>
        <script>
            // Your script goes here.
        </script>
    </body>
</html>
DOCUMENT;
// It is very important that the above line starts at column 1 (no 
// spaces before the 'DOCUMENT'), that there is nothing after the ;
// just in case, and that no other triple-angle-bracket section in
// this file is tagged as DOCUMENT. You can add another section with
// a different tag, such as DOCUMENT1 or HELLOWORLD.
die();
setcookie('SOMECOOKIE',true,time()+3600);

print HTML中是否有“id=count”元素?否则innerHTML语句将失败。但为什么不发送一个“refresh”头?
头('refresh:5'))
。倒计时对某些人来说可能很酷,但简单最有效。@lserni-谢谢你的回答,我需要倒计时,使用标题刷新对我没有帮助,你能帮我设置ID吗?你的意思是为每个客户生成一个唯一的ID吗?@Iserni-然后添加一个答案:)好吧,这不起作用了;/counter不再起作用了,刷新也不起作用了:(我已经准备了一个带有示例代码的JSFIDLE。FIDLE以不同的顺序输出数据,但是“片段”都是一样的。我看不出为什么它在PHP中不起作用。你会得到什么错误?是PHP错误,还是浏览器端错误?这是小提琴:@Iserni-我一直在测试,但没有成功。当我将它与PHP结合时,它不起我想要的作用…检查是否有cookie,如果没有显示,请等待bla bla bla。。。