PHP uses file_get_contents instead of Curl instance, curlgetcontents_php tutorial

Source: Internet
Author: User

PHP uses file_get_contents instead of curl instances, curlgetcontents


The example of this article is about PHP using file_get_contents instead of curl, and share it for everyone's reference. The implementation method is as follows:

File_get_contents instead of using curl is rare, but sometimes when you run into a server that doesn't support curl, we can use file_get_contents instead of curl, and see an example.

When all is done to discover that the server is really unable to use curl. Or if Curl does not support HTTPS. Curl HTTPS appears at 502. You don't want to re-install the site environment, you use file_get_contents instead of it.
Curl often used by curl get curl Post
Curl get substitution directly with file_get_contents ($url) is possible.
The Curl post is replaced by the following:

Copy the Code code as follows: function Post ($url, $post = null) {
$content = Http_build_query ($post);
$content _length = strlen ($content);
$options = Array (
' http ' = = Array (
' Method ' = ' POST ',
' Header ' = ' content-type:application/x-www-form-urlencoded ',
' Content ' = $post
)
);
Return file_get_contents ($url, False, Stream_context_create ($options));
}

I hope this article is helpful to everyone's PHP programming.


PHP can not get content with file_get_contents and curl

Simulating a head message
Array (' method ' = ' = ' GET ', ' header ' = ' user-agent: '. $_server[' Http_user_agent ']. " \ r \ n ")); $context = Stream_context_create ($opts); $url = dynamic.12306.cn/... 0$data = file_get_contents ($url, NULL, $context); Echo $data;? > So you can.


Using PHP's File_get_contents or curl (presented) and Echo (display)

Pure automatic input, or with people manual. If the manual is much simpler, nothing more than to write a regular page

The URL and title of the polygon. If it's purely automatic, you have to write a program that simulates your normal access

Situation, when you reach the first page, is a POST request sent, you need to send the corresponding parameters

and post requests in the past, and then the page intercepts the corresponding needs, when to access the second version of the time, send

is a GET request, this is the same time to send the parameters of the past bar, until the tenth page. PHP Tube Online has

Similar reptiles, to the next, very convenient

http://www.bkjia.com/PHPjc/907835.html www.bkjia.com true http://www.bkjia.com/PHPjc/907835.html techarticle PHP using file_get_contents instead of using curl instance, curlgetcontents This article describes the PHP use of file_get_contents instead of using curl method, share to everyone for your reference. Concrete Reality ...

  • 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.