file_get_contents returns empty string in shared host

心已入冬 提交于 2019-12-13 20:04:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!