PHP curl initialization and execution methods entry-level code _php Tutorial

Source: Internet
Author: User

PHP Curl initialization and execution method entry-level code


This article mainly introduces the PHP curl initialization and execution of the entry-level code, this article directly gives the code example, the code contains detailed comments, the need for friends can refer to the following

This is the basis of the collection, preferably familiar with

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

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 results, whether to return to the head

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 Head

curl_setopt ($this->ch, Curlopt_httpheader, Array (' user-agent:mozilla/5.0 '));

# set Post

curl_setopt ($ch, Curlopt_post, 1);

curl_setopt ($ch, Curlopt_postfields, $poststring);

# connection, execution expiration time

curl_setopt ($this->ch, Curlopt_connecttimeout, 5);

curl_setopt ($this->ch, Curlopt_timeout, 30);

# whether to 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 HTTPS

curl_setopt ($this->ch, Curlopt_ssl_verifypeer, 0);

curl_setopt ($this->ch, curlopt_ssl_verifyhost, 0);

# If you need to make a millisecond timeout, you need to 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.html www.bkjia.com true http://www.bkjia.com/PHPjc/1007647.html techarticle PHP Curl initialization and execution method entry-level code this article mainly introduces the PHP curl initialization and execution method entry-level code, this article directly gives the code example, the code contains detailed comments ...

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