Bug #75829 [NEW]: cURL and file_get_contents does not work with URL contanining special character
| From: | marco dot marsala at live dot it | Date: | Wed, 17 Jan 2018 07:53:05 +0000 |
| Subject: | Bug #75829 [NEW]: cURL and file_get_contents does not work with URL contanining special character | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213575@lists.php.net to get a copy of this message | ||
From: marco dot marsala at live dot it
Operating system: both Ubuntu and Windows
PHP version: 7.2.1
Package: URL related
Bug Type: Bug
Bug description:cURL and file_get_contents does not work with URL contanining special character
Description:
------------
cURL and file_get_contents does not work with URL contanining special
characters (for example: accented letters, quotes).
The URL sent to the remote server is badly encoded; special characters
should be encoded as urlencode() would, like any modern web browser
does.
Test script:
---------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824");
echo curl_exec($ch); // got server error page
echo
file_get_contents("https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824");
// got server error page
// my function to fix encoding
function urlencode_parts($url) {
$parts = parse_url($url);
$parts['path'] = implode('/', array_map('urlencode',
explode('/',
$parts['path'])));
$url = new \http\Url($parts);
return $url->toString();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
urlencode_parts("https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824"));
echo curl_exec($ch); // now ok
echo
file_get_contents(urlencode_parts("https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824"));
// now ok
Expected result:
----------------
The script should download the same page you can see with a web browser.
Actual result:
--------------
The server replies with a server error page.
--
Edit bug report at https://bugs.php.net/bug.php?id=75829&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75829&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75829&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75829&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75829&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75829&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75829&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75829&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75829&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75829&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75829&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75829&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75829&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75829&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75829&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75829&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75829&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75829&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75829&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75829&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75829&r=mysqlcfg