Source-php-request-2 php is more pitfall place is to achieve the same purpose, can use a variety of super means. For example, (file_get_contents, fopen, curl, fsockopen, and socket) is really difficult for a programmer with less experience. ,
So in many cases, we need to compare. Search for irresponsible resources on the Internet and make a prediction. Then compare and weigh the values.
The following is an excerpt:
Function curlRequest ($ url, $ isPost = false, $ param = array (), $ cookie = null, $ header = null, $ referer = "", $ timeout = 60) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); if (is_array ($ header )&&! Empty ($ header) {// Set header $ set_head = array (); foreach ($ header as $ k = >$ v) {$ set_head [] = "$ k: $ v ";} curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ set_head);} else {curl_setopt ($ ch, CURLOPT_HEADER, 0);} if ($ isPost = true) {curl_setopt ($ ch, CURLOPT_POST, $ isPost); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ param);} if (! Empty ($ cookie) {if (is_array ($ cookie) {$ cookies = implode (';', $ cookie) ;} else {$ cookies = $ cookie ;} curl_setopt ($ ch, CURLOPT_COOKIE, $ cookies);} if (! Empty ($ referer) {curl_setopt ($ ch, CURLOPT_REFERER, $ referer);} if ($ timeout> 0) {curl_setopt ($ ch, CURLOPT_TIMEOUT, $ timeout );} curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); $ ret = curl_exec ($ ch); if (curl_errno ($ ch) {$ ret = '';} curl_close ($ ch); return $ ret ;}
The general process will not be so complicated:
Note that curl cannot run on the console. for example, php xxx. php params_1 requires a server.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.