简体   繁体   中英

$_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..

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

example: In the browser I get : 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

I added this line to my 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"

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.

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 & .

You need to encode the URL before you send it to the 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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