从script.php中打开file.html


Open file.html from within script.php

我想从一个锚调用php脚本。

file.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>;
?>

然后一旦我的php脚本.php已经运行,我想重新打开原始文件。我试过load()和loadHTML(),都没有工作。哪个PHP函数会加载file。html?

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

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

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

echo file_get_contents("file.html");