Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction of cURL initialization and execution method of PHP

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to initialize and execute PHP cURL. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

This is the basis of collection. You'd better familiarize yourself with it.

$ch = curl_init (); # set 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/5.0')); # set postcurl_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 302curl_setopt ($this- > ch, CURLOPT_FOLLOWLOCATION, 1) Curl_setopt ($this- > ch, CURLOPT_MAXREDIRS, 10); # refercurl_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 httpscurl_setopt ($this- > ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($this- > ch, CURLOPT_SSL_VERIFYHOST, 0) # if you need to perform millisecond timeout, you need to add: curl_setopt ($this- > ch, CURLOPT_NOSIGNAL, 1); # execute $response = curl_exec ($ch); if (curl_errno ($ch)) {curl_error ($ch); exit ();} curl_close ($ch). This is the end of the introduction of cURL initialization and execution methods of PHP. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report