我有file1.php,它生成一个html网站。我有file2.html,它只包含html代码。是否可以在file1.php中创建一个生成的超链接,以链接到file2.html中的代码?我希望file1.php生成一个不依赖于file2.html是否存在的html网站。
我可以使用php的file_get_contents函数获取file2.html的内容,但是如何超链接到保存在该函数的返回中的代码呢?
例如,我单击超链接,就会看到file2.html,就像我使用任何web浏览器打开file2.html一样。我希望它看起来像是链接到一个外部文件( file2.html ),但实际上在执行file1.php生成的html网站期间,file2.html并不存在。
发布于 2012-09-08 00:45:19
file1.php
<a href="show_contents.php?file=file2.html">Link</a>show_contents.php
// perform checks to make sure $_GET['file'] exists then display contents
// you will also have to do some validation on the variable passed in to file so
// the user can't change the path to be whatever they want
echo file_get_contents($_GET['file'])基于评论的更新:
file1.php
if (isset($_GET['file')) {
// perform checks to make sure $_GET['file'] exists then display contents
// you will also have to do some validation on the variable passed in to file so
// the user can't change the path to be whatever they want
echo file_get_contents($_GET['file'])
exit();
}
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?file=file2.html">Link</a>https://stackoverflow.com/questions/12322184
复制相似问题