Warning: Curl_setopt_array(): Disabling Safe Uploads Is No Longer Supported

Larn how to deal with the irksome CURLOPT_FOLLOWLOCATION outcome using gyre in PHP

whorl is a library that lets you brand HTTP requests in PHP. The curl_exec control in PHP is a bridge to use curl from panel. curl_exec makes it like shooting fish in a barrel to rapidly and easily do GET/POST requests, receive responses from other servers like JSON and download files.

In some development environments, the execution of the post-obit code will throw the mentioned due to the usage of CURLOPT_FOLLOWLOCATION:

          <?php   $ch = curl_init();  curl_setopt( $ch, CURLOPT_URL, "http://someweb.com/some-api.json"); // URL to post  curl_setopt ($ch, CURLOPT_POST, ane); curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=Batman&password=DoYouWantToKnowMySecretIdentity"); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);// one or True // Execute $result = curl_exec( $ch );  curl_close($ch); // Prove "response" echo "Respond Response: " . $upshot;                  

In this article you'll learn why this happens and how to solve it.

Why this happens

This error happens when your PHP configuration disallow you from following a location.

Thanks captain obvious

Possible solutions

As in every environment and cases, not all of the listed options will piece of work for you:

1. Set the CURLOPT_FOLLOWLOCATION to false

The CURLOPT_FOLLOWLOCATION option indicates wheter if ringlet should follow HTTP 3xx redirects or not. When y'all request a URL, you can sometimes be redirected to some other URL, for case in PHP you can redirect using:

          header('Location: http://example.com/');        

By default, this option is disabled and normally, there'south no good reason to disable information technology, yet if y'all know what you're doing and you're pretty sure that your asking will be never redirected, then you can merely disable the option:

          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, Fake);        

ii. Disable safe mode of PHP

Condom style is an effort to solve some of the problems that are introduced when running a PHP enabled web server in a shared hosting environment. The additional security checks imposed past Safe Mode are, notwithstanding, performed at the PHP level, since the underlying web server and operating system security architecture is usually not sufficient to impose the necessary security restrictions for a multi-user environs, in which many users may be able to upload and execute PHP lawmaking.

Enabling Safe Mode imposes several restrictions on PHP scripts, these restrictions are mostly concerned with file access, access to surround variables and controlling the execution of external processes. These restrictions affects cURL when the FOLLOWLOCATION options is enabled, therefore in case you lot can't disable that option in whorl, in club to make your script work, you'll need to disable the safe style by modifying your php.ini file.

Use any lawmaking or text editor and edit your php.ini file and search for the safe_mode option and set Off every bit value, as information technology probably already with On.

Disable safe mode PHP

Restart apache and try again to execute your script. Alternatively, if you can't alter the php.ini file in your environment, you can try to set up this property dinamically with PHP in your script using:

          ini_set('safe_mode', imitation);        

Although the second way information technology'southward unlikely to work for most of the developers, it's worth a attempt.

3. Set open_basedir to none

The open_basedir function defines the locations or paths from which PHP is allowed to access files using functions similar fopen() and gzopen(). If a file is exterior of the paths defined by open_basedir, PHP will refuse to open it. You cannot utilize a symbolic link as a workaround, considering the path that the symbolic link resolves to falls nether the restrictions of the open_basedir function.

To disable the open_basedir option we just need to comment it in the php.ini file. Open a code or text editor and edit the php.ini file, search the open_basedir choice and annotate past prefixing information technology with ;:

          ; open_basedir, if prepare, limits all file operations to the defined directory ; and below.  This directive makes most sense if used in a per-directory ; or per-virtualhost web server configuration file. ; http://php.internet/open-basedir ;open_basedir =        

Save the changes, restart apache and try to execute your script over again.

You can either, in your server if y'all use Plesk to modify the open_basedir from a GUI. Open up plesk, navigate to your domain and open PHP Settings.

PHP Settings Plesk

At present proceed from the list, to search for open_basedir and select none from the list:

open_basedir Plesk

Salve the changes and attempt to execute your script again.

Honorable mentions

If you employ a library like Unirest and you lot get such an error, you can try the kickoff choice by setting the CURLOPT_FOLLOWLOCATION option to imitation without modifying the library source code using:

          Unirest\Request::curlOpts(array(     CURLOPT_FOLLOWLOCATION => fake ));        

Don't forget to share with the community which pick did work for you, happy coding !

taylordinectich.blogspot.com

Source: https://ourcodeworld.com/articles/read/312/how-to-solve-php-curl-warning-curl-set-opt-array-curlopt-followlocation-cannot-be-activated-when-an-open-basedir-is-set

0 Response to "Warning: Curl_setopt_array(): Disabling Safe Uploads Is No Longer Supported"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel