note 92994 added to function.file-get-contents

From: Date: Tue, 18 Aug 2009 19:57:31 +0000
Subject: note 92994 added to function.file-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-159612@lists.php.net to get a copy of this message
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 "&amp;" 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&amp;value=abc&amp;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 ---- Server IP: 209.41.74.194 Probable Submitter: 68.166.55.106 ---- Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php Edit -- https://master.php.net/note/edit/92994 Del: integrated -- https://master.php.net/note/delete/92994/integrated Del: useless -- https://master.php.net/note/delete/92994/useless Del: bad code -- https://master.php.net/note/delete/92994/bad+code Del: spam -- https://master.php.net/note/delete/92994/spam Del: non-english -- https://master.php.net/note/delete/92994/non-english Del: in docs -- https://master.php.net/note/delete/92994/in+docs Del: other reasons-- https://master.php.net/note/delete/92994 Reject -- https://master.php.net/note/reject/92994 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159612) next »