Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'&' becomes '&' when trying to get contents from a URL

I was running my WebServer for months with the same Algorithm where I got the content of a URL by using this line of code:

$response = file_get_contents('http://femoso.de:8019/api/2/getVendorLogin?' . http_build_query(array('vendor'=>$vendor,'user'=>$login,'pw'=>$pw),'','&'));

But now something must have changed as out of sudden it stopped working.

In earlier days the URL looked like it should have been:

http://femoso.de:8019/api/2/getVendorLogin?vendor=100&user=test&pw=test

but now I get an error in my nginx log saying that I requested the following URL which returned a 403

http://femoso.de:8019/api/2/getVendorLogin?vendor=100&user=test&pw=test

I know that something changed on the target server, but I think that shouldn't affect me or not?!

I already spent hours and hours of reading and searching through Google and Stackoverflow, but all the suggested ways as

urlencode() or htmlspecialchars() etc...

didn't work for me.

For your information, the environment is a zend application with a nginx server on my end and a php webservice with apache on the other end.

Like I said, it changed without any change on my side!

Thanks

like image 679
Evils Avatar asked Jan 29 '26 05:01

Evils


2 Answers

Let's find out the culprit!


1) Is it http_build_query ? Try replacing:

'http://femoso.de:8019/api/2/getVendorLogin?' . http_build_query(array('vendor'=>$vendor,'user'=>$login,'pw'=>$pw)

with:

"http://femoso.de:8019/api/2/getVendorLogin?vendor={$vendor}&user={$login}&pw={$pw}"


2) Is some kind of post-processing in the place? Try replacing '&' with chr(38)


3) Maybe give a try and play a little bit with cURL?

$ch = curl_init();

curl_setopt_array($ch, array(
    CURLOPT_URL => 'http://femoso.de:8019/api/2/getVendorLogin?' . http_build_query(array('vendor'=>$vendor,'user'=>$login,'pw'=>$pw),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => true, // include response header in result
    //CURLOPT_FOLLOWLOCATION => true, // uncomment to follow redirects
    CURLINFO_HEADER_OUT => true, // track request header, see var_dump below
));

$data = curl_exec($ch);
curl_close($ch);

var_dump($data, curl_getinfo($ch, CURLINFO_HEADER_OUT));
exit;
like image 183
Gras Double Avatar answered Jan 31 '26 19:01

Gras Double


Sounds like your arg_separator.output is set to "&" in your php.ini. Either comment that line out or change to just "&"

like image 39
Corey Avatar answered Jan 31 '26 18:01

Corey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!