简体   繁体   English

$ _REQUEST [“ url”]未获取完整的URL

[英]$_REQUEST[“url”] not get the full url

I'm trying to load a facebook url by using "file_get_contents", then "htmlentities" and finally "explode" , to extract the video url.. 我试图通过使用“ file_get_contents”,然后是“ htmlentities”,最后是“ explode”来加载一个Facebook URL,以提取视频URL。

my problem, when put the link in the php work fine , but when I use $_REQUEST["url"] , I get the link shorter than the sent one 我的问题,当将链接放入php时工作正常,但是当我使用$_REQUEST["url"] ,我得到的链接比发送的链接短

example: In the browser I get : https://m.facebook.com/story.php?story_fbid=726043457734682&id=520394245009393&_rdr 示例:在浏览器中,我得到: https : //m.facebook.com/story.php?story_fbid=726043457734682&id=520394245009393&_rdr

but if I print it from the PHP will be : https://m.facebook.com/story.php?story_fbid=72604345773468 但是如果我从PHP打印,它将是: https : //m.facebook.com/story.php?story_fbid=72604345773468

I added this line to my PHP: 我将此行添加到我的PHP中:

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

I tried to use "$_GET" 我尝试使用“ $ _GET”

nothing works :( 没有用:(

I tried a lot of codes but nothing worked for my issue , or maybe I didn't know how to use .... please help me with an example. 我尝试了很多代码,但没有解决我的问题,或者也许我不知道如何使用....,请帮我举个例子。

something like this I want: 我想要这样的东西:

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

Thank you .. 谢谢 ..

The problem is with the URL you are using to request the PHP script. 问题在于您用来请求PHP脚本的URL。

You have something like this: 你有这样的事情:

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

The & character has special meaning in a query string. &字符在查询字符串中具有特殊含义。 It separates values. 它分隔值。

This gives you: 这给您:

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

This is why your Facebook URL is being cut off at the & . 这就是为什么您的Facebook URL在&处被切断的原因。

You need to encode the URL before you send it to the PHP. 在将URL发送到PHP 之前,需要对其进行编码。

At a bare minimum, the & needs to be replaced with %26 , but you should use a function that replaces all the special characters such as JavaScript's encodeURIComponent or PHP's urlencode . 至少需要将&替换为%26 ,但是您应该使用一个函数来替换所有特殊字符,例如JavaScript的encodeURIComponent或PHP的urlencode

This will give you: 这将为您提供:

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

Fixing the input to your script, as described above, is the correct and easiest way to fix this. 如上所述,将输入修复为脚本是正确且最简单的方法。

If you absolutely cannot fix the raw input data, then you would need to access the raw data in the URL (with $_SERVER[REQUEST_URI] ) and parse it yourself. 如果您绝对不能修复原始输入数据,则需要访问URL中的原始数据(使用$_SERVER[REQUEST_URI] )并$_SERVER[REQUEST_URI]解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM