PHP cURL initialization and execution method entry-level code
This is the basis for collection, it is best to be familiar with it
$ch = curl_init(); # Set the url and return the result, whether to return to the headercurl_setopt($ch, CURLOPT_URL, '/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->ch, CURLOPT_HEADER, 1); # cookie file settingscurl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($this->ch, CURLOPT_COOKIEFILE, $cookie_file); # Extra headcurl_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 timecurl_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); # refer curl_setopt($this->ch, CURLOPT_REFERER, $refer); # http version and port reuse settingscurl_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 millisecond timeout is required, add:curl_setopt($this->ch, CURLOPT_NOSIGNAL, 1); # implement$response = curl_exec($ch); if(curl_errno($ch)){ curl_error($ch); exit(); } curl_close($ch);
Related Articles
Examples of dynamic settings automatic completion and automatic verification of new ThinkPHP3.1
This article mainly introduces the automatic completion and automatic verification of ThinkPHP3.1 dynamic settings. Friends who need it can refer to it.2014-06-06Implement red and blue (top step) voting code based on PHP+jQuery+MySql
When the two parties have different opinions, it is necessary to reach an agreement by voting. This article introduces the red and blue (top-step) voting code based on PHP+jQuery+MySql through examples. Friends who need it can refer to it2015-08-08Detailed explanation of the where method of ThinkPHP CURD method
This article mainly introduces the where method of ThinkPHP CURD method. Friends who need it can refer to it.2014-06-06In-depth analysis of php's sphinx
This article provides a detailed analysis and introduction to the use of sphinx in php. For those who need it, please refer to it.2013-05-05Laravel's example explanation of using redis queue
This article mainly introduces the example of using the redis queue for laravel. It is very simple to configure redis after using the laravel framework. Interested students can learn it2021-03-03Implementation of variables inside PHP7 (I)
This article mainly introduces the relevant information about the implementation of variables within PHP7 (I). Friends who need it can refer to it.2015-12-12Yii2 hasOne(), hasMany() Methods to implement three table association (two types)
This article mainly introduces the method (two) of three table associations in Yii2 hasOne() and hasMany(). It is very good and has reference value. Friends who need it can refer to it.2017-02-02Example of code for downloading files in php
PHP download file code example, friends who need it can refer to it2012-06-06Detailed interpretation of low memory utilization and weak types of PHP arrays
This article mainly introduces a detailed interpretation of the low memory utilization and weak types of PHP arrays, which has certain reference value. Interested friends can refer to it.2017-08-08How to filter other website links in html by PHP (domain whitelist function)
This article mainly introduces the method of filtering other website links in html by PHP (domain whitelist function). Friends who need it can refer to it2014-04-04