How to avoid URL binding with PHP cURL?

I have a URL (slightly modified), for example:

https://ssl.site.com/certificate/123/moo.shoo?type=456&domain=$GH$%2fdodo%20[10%3a47%3a11%3a3316]

This does not work the way I assume when passed directly to PHP cURL due to parentheses.

I managed to run the same URL on the command line as follows:

curl -g "https://ssl.site.com/certificate/123/moo.shoo?type=456&domain=$GH$%2fdodo%20[10%3a47%3a11%3a3316]"

Is there an option (similar to -g to disable globbing) that I can use in PHP cURL? If not, how can I encode or format my URL before passing it to PHP cURL?

+3
source share
2 answers

I am currently using this and it seems to work

$urlReconstructed = str_replace(']', '%5D', str_replace('[', '%5B', $url));
+1
source

This seems to work for me:

$urlParts = parse_url($url);    
parse_str($urlParts['query'], $queryParts);
$urlReconstructed = sprintf('%s://%s%s?', $urlParts['scheme'], $urlParts['host'], $urlParts['path']);

foreach ($queryParts as $key => $value)
{
  $urlReconstructed .= $key . "=" . urlencode($value);
}

echo $urlReconstructed;

, Pekka, . , .

0

Source: https://habr.com/ru/post/1795121/


All Articles