Fopen does not work on my server

It works fine on localhost with Xampp, but when I try it on my server (host-ed.net), fopen cannot open any URL, it only works for files without http.

<?php $file="http://www.google.es"; $gestor = fopen($file, "r") or die ("Nothing"); ?> 

On my server with this code Nothing is displayed. Maybe something on php.ini?

EDIT: In php.ini: allow_url_fopen = On

EDITOR: He decided. My server turned it off, but now it is turned on. Thanks for answers.

+6
source share
7 answers

fopen cannot open any URL

Check the value of allow_url_fopen php.ini parameter:

 var_dump(ini_get('allow_url_fopen')); 

This is probably not true. You need to talk to your web host or try another method. Is Mabye CURL turned on?

You should also check for error_reporting and display_errors . PHP should have loudly complained that it could not open the URL. You will want to turn both of them during code development so that you can understand what will go wrong.

+8
source

Permission to open URLs with fopen controlled by the php.ini parameter allow_url_fopen . You can see the current setting using phpinfo() , which will upload an html document containing all the settings for your server.

+2
source

Like the http://php.net/manual/en/function.fopen.php state,

If the file name is in the form "scheme: // ...", it is assumed that it is a URL, and PHP will look for a protocol handler (also known as a wrapper) for this scheme. If no wrappers for this protocol are registered, PHP will issue a notification to help you keep track of potential problems in the script, and then continue as if the file name indicates a regular file.

Therefore, I assumed that the URL was not registered, and php treats this as a regular file name that does not exist.

0
source

Try Curl, it will work if it is installed on this web server.

0
source

Do you have a free account? Most hosting services restrict outgoing connections to free accounts to prevent abuse. Try the following:

 $fp = fsockopen("some.alive.site", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { echo "Everything is OK"; fclose($fp); } 

If you see an error message, you are not allowed to make outgoing connections.

0
source

If you are using PHP-FPM, check the configuration files in pool.d/ . PHP-FPM pools can override php settings using php_admin_flag , php_admin_value , php_flag or php_value . (We ran into this on Ubuntu 16 vps)

0
source

Source: https://habr.com/ru/post/907064/


All Articles