note 92994 deleted from function.file-get-contents by danbrown
| From: | danbrown@php.net | Date: | Tue, 18 Aug 2009 19:59:58 +0000 |
| Subject: | note 92994 deleted from function.file-get-contents by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159613@lists.php.net to get a copy of this message | ||
Note Submitter: tech-info at nwmagic dot net
----
Something that cost me over 6 hours of fighting the machine - if the filename string you pass is a
URL (assuming fopen wrappers have been enabled), then the special characters that the note for this
function warns you about ("Note: If you're opening a URI with special characters, such as
spaces, you need to encode the URI...") INCLUDES the ampersand ("&"). The
"&" is apparently converted to "&" INTERNAL TO THE FUNCTION and
passed to the URL you specified. This caused Error 403's in my application, which were reported
in my Apache error log, but no where else.
But if you urlencode() the "&", then it is considered DATA and not a field separator,
so that the server end of the connection just gets one, long $_GET variable. The "?" seems
to work correctly, so you can pass *one* $_GET variable.
Example:
<?php
$fetch_url="http://www.example.com/return_data.php"
.
"?id=123&value=abc&pass=456";
$work1=file_get_contents($fetch_url);
// The URL the Apache error log reported (HTTP Error 403):
// "http://www.example.com/return_data.php
?id=123&value=abc&pass=456"
// (I added the SPACE before the "?" on the line above, because I had to to enter this
note.)
?>
This returned an empty string for me because what was sent to the website caused error 403's.
And as far as I can tell there is no way to tell that there was an error, except by looking in the
Apache error log. (And the fact that the return string was empty, which indicated an error in my
case, but told me nothing about where to look or what to look for!)
However, if curl is installed (libcurl/7.15.5), curl works perfect (both the libraries and the
executable).
This issue happened with PHP 4.4.4