简体   繁体   中英

PHP - Problem using file_get_contents

I have a problem while using the file_get_contents function. I am using it to get a response from a different web server, but it's not returning anything (shown as empty string using var_dump). Also, the problem is only while calling this specific server, because I got result when I used Google's address; and it's working fine in my local machine. I've tried cUrl too - but same result.

Could you do:

echo ini_get('allow_url_fopen');

If this is false, you should try setting it to true in your php.ini before calling file_get_contents.

Maybe you need to set the user agent? Some sites may check this and disallow bots.

ini_set('user_agent', 'Name of your bot');

It might be issue with the server you are calling is the file with the appropriate permissions and is it accessible from a normal web browser? If the file access is restricted by IP is your server'sIP allowed?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM