从 script.php 中打开 file.html

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7030689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:50:41  来源:igfitidea点击:

Open file.html from within script.php

phpredirect

提问by Albion

I want to call a php script from an Anchor.

我想从 Anchor 调用 php 脚本。

file.html

文件.html

<body>
    <a href="file.php?id=1">Click</a>
</body>

script.php

脚本文件

<?php

    $id = $_GET['id'];

    ... <do some stuff>;

    <when finished doing some stuff reload file.html>;

?>

Then once my php in script.php has run I want to reopen the original file. I've tried load() and loadHTML(), neither has worked. What PHP function will load file.html?

然后一旦我在 script.php 中的 php 运行,我想重新打开原始文件。我试过 load() 和 loadHTML(),都没有奏效。什么 PHP 函数会加载 file.html?

Thanks so much.

非常感谢。

回答by derekerdmann

You'll want to redirect the user to the original page:

您需要将用户重定向到原始页面:

header( 'Location: http://example.com/file.html' );

Just make sure you don't output anything (send data to the browser) before redirecting.

只需确保在重定向之前不输出任何内容(将数据发送到浏览器)。

回答by smutty

echo file_get_contents("file.html");