javascript - HTML 文件的 PHP file_get_contents 请求旧资源
问题描述
我有一个特定的网页。这是文件结构:
index.php
script.js
style.css
edit
|
|--- index.php
|
|--- script.js
edit/index.php
正在回显index.php
using file_get_contents('../index.php')
which contains的内容<script src='script.js'></script>
。edit/script.js
包含alert()
. 当我打开https://www.example.com/edit
时,它显示的内容index.php
,但它不执行里面的代码edit/script.js
。为什么会发生这种情况,我该如何解决?(虽然index.php
有扩展.php
它不包含任何 PHP,只是 HTML)
解决方案
问题是浏览器不知道它edit
实际上是edit/index.php
. 它认为这是根目录中的文件,因此在解析时script.js
也会在根目录中查找该文件。
您应该配置网络服务器,以便它执行从edit
到的重定向edit/index.php
,而不仅仅是返回 的内容edit/index.php
。这样,所有相对 URL 都将被正确处理。如果您不想显示脚本名称,您可以重定向到edit/
-- 这足以让它知道这是一个目录而不是文件。
推荐阅读
- javascript - QML WebView 无法运行 javascript
- react-native - RN expo 独立应用程序在 LAN 环境中使用 Authsession,可能吗?
- python - 匹配数据框之间的行并保持顺序
- javascript - 显示隐藏的 div 不是下推其他内容,而是在页面的另一部分
- mysql - 是否可以要求 ProxySQL 在读取时使用特定的 GTID?
- python - arg_parse 无或列出熊猫 read_table
- c# - 使用正则表达式提取组并在一行中构造 URL
- javascript - 如何展平对象内部的数组?
- android - 如何使用 CodeceptJS 在 Appium 中识别带有 id 的字段?
- sql - 我可以在 SQL Server 上创建动态表值函数吗?