首页 > 解决方案 > 在html源码中使用PHP更改链接地址

问题描述

嘿,谢谢你检查我

---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.jpghttp://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

如果您可以编辑我的代码来修复那将是最好的,因为我添加代码非常糟糕

标签: phpproxy

解决方案


如果您正在使用,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。


推荐阅读