php - 在html源码中使用PHP更改链接地址
问题描述
嘿,谢谢你检查我
现在正在尝试学习如何在 php 中编写代码,以修复一个简单的 Url 代理,它只需将 url 放在www.Proxy.info/?u=之后即可工作,并且一切正常,除了它不会更改嵌入的文件路径
所以在我试图代理的网站的源代码中,我有一个这样的地址,/images/image.jpg
或者https://Somesite.com/js/file.js
导致问题,因为现在代理的网站认为我的服务器上有文件
我需要添加到我的代理服务器地址(www.Proxy.info/?u=),以便它将使用现在代理的站点文件并使其工作,例如http://www.Proxy.info/?u=/images/image.jpg
或http://www.Proxy.info/?u=https://Somesite.com/js/file.js
有一个代理可以做到这一点,但它使用的是 nginx,我不太喜欢 nginx,这是第二个例子,有点简单
我有它作为
https://www.proxy.info/lib/fonts/source-code-pro-v14-latin-regular.woff2
但我需要它
https://www.proxy.info/?u=https://www.Somesite.com/lib/fonts/source-code-pro-v14-latin-regular.woff2
或者
https://www.Proxy.info/?u=Somesite.com/lib/fonts/source-code-pro-v14-latin-regular.woff2
如果您可以编辑我的代码来修复那将是最好的,因为我添加代码非常糟糕
解决方案
如果您正在使用,html form
则设置表单方法GET
和输入字段name="u"
并使用 php$_GET['u']
捕获查询 url。这是我的评论,但现在无法评论。此外,您没有共享 php 代码,因为不完全确定必须在哪里添加/进行更改。请更新您的帖子/代码。
更新答案:
我看到你使用这个 github 开源:php-ultra-small-proxy
使用此完整代码index.php
:
<?php
set_time_limit(0);
include __DIR__.'/UltraSmallProxy.php';
if(isset($_GET['u']))
{
$url = $_GET['u'];
$proxy = new UltraSmallProxy();
$output = $proxy->load($url); // <-- specify start page here
echo $output;
}
?>
<form method="GET">
<input type="url" name="u" placeholder="Enter proxy visit url" required>
<input type="submit" value="go">
</form>
我曾经isset() Function
检查变量是否为空/设置/声明。另一件事是$_GET
,它是一个 php 超级全局变量和参数u
。添加这个超级全局变量和参数,你会得到这样的 ( https://www.proxy.info/?u=https://www.Somesite.com/lib/fonts/source-code-pro-v14-latin-regular.woff2
) 获取请求 url。
推荐阅读
- python - 删除或合并熊猫数据框中的多索引列而不丢失数据
- python - zlib TypeError:需要一个类似字节的对象,而不是“str”
- php - 无法在 PHP 站点中检索 MySQL 数据
- unity3d - 如何让强化学习代理学习永无止境的跑步者?
- javascript - Jquery弹出模型内容向下滚动问题
- html - 项目加载时更改 Typescript 中的样式
- java - 没有可用的节点 elasticsearch
- javascript - 保存会话变量错误的时间间隔
- javascript - 无法从javascript设置fancybox iframe
- java - 更新我的应用程序后,它与旧版本不匹配