【问题标题】:$_REQUEST["url"] not get the full url$_REQUEST["url"] 没有得到完整的 url
【发布时间】:2018-10-05 15:48:29
【问题描述】:

我正在尝试通过使用“file_get_contents”,然后是“htmlentities”,最后是“explode”来加载一个 facebook url,以提取视频 url..

我的问题,当把链接放在 php 中时工作正常,但是当我使用$_REQUEST["url"] 时,我得到的链接比发送的短

示例: 在浏览器中我得到:https://m.facebook.com/story.php?story_fbid=726043457734682&id=520394245009393&_rdr

但如果我从 PHP 中打印出来,则为:https://m.facebook.com/story.php?story_fbid=72604345773468

我在我的 PHP 中添加了这一行:

ini_set('user_agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/60.0');

我尝试使用“$_GET”

没有用 :(

我尝试了很多代码,但没有解决我的问题,或者我不知道如何使用....请帮我举个例子。

我想要这样的东西:

$url = $_REQUEST["url"];
$lines = file_get_contents($url);
$page = htmlentities($lines);

谢谢你..

【问题讨论】:

    标签: php html url request file-get-contents


    【解决方案1】:

    问题在于您用于请求 PHP 脚本的 URL。

    你有这样的东西:

    http://example.com/your.php?url=http://something/?foo=1&bar=2
    

    & 字符在查询字符串中具有特殊含义。它分隔值。

    这给了你:

    url = http://something/?foo=1
    bar = 2
    

    这就是您的 Facebook URL 在& 处被截断的原因。

    您需要在发送到 PHP 之前对 URL 进行编码。

    至少,& 需要替换为 %26,但您应该使用替换所有特殊字符的函数,例如 JavaScript 的 encodeURIComponent 或 PHP 的 urlencode。

    这会给你:

    http://example.com/your.php?url=http%3A%2F%2Fsomething%2F%3Ffoo%3D1%26bar%3D2
    

    如上所述,修复脚本的输入是解决此问题的正确且最简单的方法。

    如果您绝对无法修复原始输入数据,那么您需要访问 URL 中的原始数据(使用 $_SERVER[REQUEST_URI])并自行解析。

    【讨论】:

    • 感谢您的回答我做了一些更改:$url = "{$_SERVER['REQUEST_URI']}"; $split = explode("url=", $url); $url = $拆分[1]; $url = str_replace("www","m",$url); $lines = file_get_contents($url);现在的 url 是正确的,但是当我使用 file_get_contents 时,然后是 htmlentities。在某些情况下有效,其他情况下没有,任何想法?这行得通:m.facebook.com/… 这行不通:m.facebook.com/100021930886799/posts/352071335533893
    猜你喜欢
    • 1970-01-01
    • 2021-02-07
    • 2017-02-13
    • 2012-11-06
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    相关资源
    最近更新 更多