Php curl is provided to obtain the redirection file with 301-302 errors. Solution: Download the documentation for free. Abstract: php curl retrieval has a file jump error of 301-302 solve the PHP cURL library simple and effective web page capture using PHP cURL library can easily and effectively capture the web page. You only need to run a script, analyze the web page you crawled, and then you can
Php curl retrieval contains 301-302 redirection file error Solution
PHP cURL library easily and effectively captures webpages
Using the PHP cURL library, you can easily and effectively capture webpages. You only need to run a script, analyze the web page you crawled, and then you can get the data you want as a program. Whether you want to retrieve part of the data from a link or an XML file and import it to the database, you may simply get the webpage content, cURL is a powerful PHP library. This article describes how to use this PHP library.
Enable cURL settings
First, we must first determine whether PHP has enabled this library. You can use the php_info () function to obtain this information.
If you can see the following output on the webpage, it indicates that the cURL library has been enabled.
If you see this, you need to set your PHP and enable this library. If you are on Windows, it is very simple. You need to modify the settings of your php. ini file, find php_curl.dll, and cancel the semicolon comment. As follows:
If you are in Linux, You need to recompile your PHP. During editing, you need to open the compilation parameter -- add the "-with-curl" parameter to the configure command.
A small example
If everything is ready, the following is a small routine:
// Initialize a cURL object
$ Curl = curl_init ();
// Set the URL you want to capture
Curl_setopt ($ curl, CURLOPT_URL, 'https: // www.php1.cn ');
// Set the header
Curl_setopt ($ curl, CURLOPT_HEADER, 1 );
// Set the cURL parameter to save the result to the string or output to the screen.
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );
// Run cURL to request the webpage
$ Data = curl_exec ($ curl );
// Close the URL request
Curl_close ($ curl );
// Display the obtained data