If you run CURLOPT_FOLLOWLOCATION in PHP and then get the php prompt error message:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set…
Error Mentioning the two key words safe_mode and open_basedir, if you are a virtual host and do not have permission to set APPCHE, you cannot solve the problem by modifying the server configuration. Generally speaking, the server configuration safe_mode is off, and then there are some security requirements for users. Restriction, by setting open_basedir to limit the PHP execution folder of the virtual host user, so when you use CURLOPT_FOLLOWLOCATION (php curl function, deep capture data), the error message mentioned in the article will appear once there is a 301 redirect, etc.
After checking the relevant information, I quickly found the solution, http://www.php.cn/php-weizijiaocheng-362563.html. These methods are all available in the official php help.
The specific method is in curl Whether to use curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true) in the statement, customize a function in the php function,
The code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
After the function is defined, replace the statement curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true) with curl_redir_exec($ch)
After this, I think your PHP file should not prompt an error. Regarding this code, you can find it in the official PHP connection.
The official code of PHP is as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
【Related articles Recommended】
1. Introduction to the concept and usage of php curl_setopt function
2.A simple example of using the php curl_setopt() function to capture web pages and POST data
3.An example of php curl_setopt function simulating user login
4.Detailed explanation of usage examples of PHP curl_exec function
The above is the detailed content of Warning: curl_setopt() [function.curl-setopt]: CURLO...how to solve the error when using php curl function. For more information, please follow other related articles on the PHP Chinese website!