首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建指向更多HTML代码的HTML链接

问创建指向更多HTML代码的HTML链接
EN

Stack Overflow用户
提问于 2012-09-08 00:41:21
回答 1查看 120关注 0票数 0

我有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并不存在。

EN

回答 1

Stack Overflow用户

发布于 2012-09-08 00:45:19

file1.php

代码语言:javascript
复制
<a href="show_contents.php?file=file2.html">Link</a>

show_contents.php

代码语言:javascript
复制
// 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

代码语言:javascript
复制
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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12322184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档