问题
I'm trying get url contents with file_get_contents(), its works in my localhost server, but in shared host server, the function returns a empty string, without errors. My code follows:
$uri = 'http://my_url.com:81/datasnap/rest/TServerMethods/getLoginCliente/galf/123/';
$result = file_get_contents($uri);
var_dump($result);
and the result is:
string(0) ""
instead of:
{result: [4532,1]}
I'm test change the url for google.com, and works perfectly.
Anyone know why this happens?
回答1:
Check if fopen url wrappers are enabled :
var_export(ini_get('allow_url_fopen'));
I suppose it is just disabled as potentially insecure operation.
回答2:
the problem is the firewall host. The firewall is block the port 81.
回答3:
Add this at the top of your php file
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
And then look for any errors that it gives you. the shared host might have disabled that particular function and in order to have it work you'll have to ask them to enable it.
来源:https://stackoverflow.com/questions/13782699/file-get-contents-returns-empty-string-in-shared-host