PHPcURL initialization and execution method entry-level code _ PHP Tutorial

Source: Internet
Author: User
PHPcURL initialization and execution method entry-level code. PHPcURL initialization and execution method entry-level code this article mainly introduces the PHPcURL initialization and execution method entry-level code. This article provides a sample code that contains detailed comments on PHP cURL initialization and execution method entry-level code

This article mainly introduces PHP cURL initialization and execution method entry-level code. This article provides a code example that contains detailed comments. For more information, see

This is the basis for data collection.

?

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

45

46

$ Ch = curl_init ();

# Set the url and return the result, whether to return the header

Curl_setopt ($ ch, CURLOPT_URL, 'http: // www.baidu.com /');

Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );

Curl_setopt ($ this-> ch, CURLOPT_HEADER, 1 );

# Cookie file settings

Curl_setopt ($ this-> ch, CURLOPT_COOKIEJAR, $ cookie_file );

Curl_setopt ($ this-> ch, CURLOPT_COOKIEFILE, $ cookie_file );

# Extra header

Curl_setopt ($ this-> ch, CURLOPT_HTTPHEADER, array ('User-Agent: Mozilla/123456 '));

# Set post

Curl_setopt ($ ch, CURLOPT_POST, 1 );

Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ poststring );

# Connection and execution expiration time

Curl_setopt ($ this-> ch, CURLOPT_CONNECTTIMEOUT, 5 );

Curl_setopt ($ this-> ch, CURLOPT_TIMEOUT, 30 );

# Follow 301 302

Curl_setopt ($ this-> ch, CURLOPT_FOLLOWLOCATION, 1 );

Curl_setopt ($ this-> ch, CURLOPT_MAXREDIRS, 10 );

# Refer

Curl_setopt ($ this-> ch, CURLOPT_REFERER, $ refer );

# Http version and Port reuse settings

Curl_setopt ($ this-> ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );

Curl_setopt ($ this-> ch, CURLOPT_FORBID_REUSE, 1 );

# Support for https

Curl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYPEER, 0 );

Curl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYHOST, 0 );

# If millisecond timeout is required, add:

Curl_setopt ($ this-> ch, CURLOPT_NOSIGNAL, 1 );

# Execution

$ Response = curl_exec ($ ch );

If (curl_errno ($ ch )){

Curl_error ($ ch );

Exit ();

}

Curl_close ($ ch );

Http://www.bkjia.com/PHPjc/1007647.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1007647.htmlTechArticlePHP cURL initialization and execution method entry-level code this article mainly introduces PHP cURL initialization and execution method entry-level code, this article directly gives the sample code, the code contains detailed notes...

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.