Enable allow_url_fopen in php ini

This article describes how to enable and disable the allow_url_fopen directive in a custom php.ini file.

The information in this article only applies to certain types of hosting accounts. To determine whether or not the information below applies to your account, please see this article.

This article assumes that you have already set up a custom php.ini file on your web site. If you have not already set up a custom php.ini file, please read this article first.

Using the allow_url_fopen directive

The allow_url_fopen directive is disabled by default. You should be aware of the security implications of enabling the allow_url_fopen directive. PHP scripts that can access remote files are potentially vulnerable to arbitrary code injection.

When the allow_url_fopen directive is enabled, you can write scripts that open remote files as if they are local files. For example, you can use the file_get_contents function to retrieve the contents of a web page.

To enable this functionality, use a text editor to modify the allow_url_fopen directive in the php.ini file as follows:

allow_url_fopen = on

To disable this functionality, modify the allow_url_fopen directive in the php.ini file as follows:

allow_url_fopen = off

To verify the current value of the allow_url_fopen directive and other directives, you can use the phpinfo[] function. For more information, please see this article.

More Information

  • To view a complete list of php.ini directives, please visit //www.php.net/manual/en/ini.list.php.
  • For more information about the allow_url_fopen directive, please visit //www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen.
  • For more information about the file_get_contents function, please visit //www.php.net/file_get_contents.

We are going to see:

Introduction Introduction

allow_url_fopen is a filesystem and streams configuration option. Which enables the URL-aware fopen[] wrappers that enable accessing URL objects like files.

If allow_url_fopen[] is enabled then by default we can access remote files using the FTP or HTTP protocol.

Also, extensions like zlib may register additional wrappers.

Top ↑

Issue Issue

We could not use the fopen[] if the option allow_url_fopen is DISABLED from the server.

If it is enabled then you can disable it for testing purposes by adding code allow_url_fopen=Off in your php.ini file. Also, After updating the php.ini file don’t forget to restart the apache server.

Now, Let’s assume that we have below code in the file C:/xampp/htdocs/tutorials/index.php:

Bài mới nhất

Chủ Đề