Php Curl gets 301-302 Jump file error problem solved

Source: Internet
Author: User
Keywords Php Curl gets 301-302 Jump file error problem solved
php Curl gets 301-302 Jump file error problem solved

PHP's Curl Library is simple and effective in grasping web pages

Using the PHP Curl Library, you can easily and effectively grab pages. You just need to run a script, then analyze the page you crawled, and then you can get the data you want in a program. Whether you want to take part of the data from a link, or take an XML file and import it into the database, the fear is simply to get the Web content, CURL is a powerful PHP library. This article mainly describes if you use this PHP library.

Enable CURL settings

First, we have to make sure that our PHP opens the library, and you can get this information by using the Php_info () function.

If you can see the following output on a webpage, it means that the Curl Library is turned on.

If you see, then you need to set up your PHP and open the library. If you are under the Windows platform, then very simple, you need to change the settings of your php.ini file, find Php_curl.dll, and cancel the previous semicolon comment on the line. As shown below:

If you are under Linux, then you need to recompile your PHP, and when editing, you need to open the compile parameters--Add the ―–with-curl‖ parameter to the Configure command.

A small example

If everything is ready, here is a small routine:

Initialize a CURL object

$curl = Curl_init ();

Set the URL you need to crawl

curl_setopt ($curl, Curlopt_url, ' http://www.php.cn ');

Set Header

curl_setopt ($curl, Curlopt_header, 1);

Sets the curl parameter, which requires the result to be saved to a string or output to the screen.

curl_setopt ($curl, Curlopt_returntransfer, 1);

Run Curl, request a Web page

$data = curl_exec ($curl);

Close URL Request

Curl_close ($curl);

Show the data obtained

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.