Detailed explanation of obtaining email address based on PHP CURL_PHP tutorial
WBOY
Release: 2016-07-21 15:09:55
Original
832 people have browsed it
CURL can be described as a must-have killer medicine for home travel. Why is it so described? It is because it is easy to use and can realize a series of functions such as page grabbing, simulated login collection and so on. I remember that the first time I came into contact with CURL was to complete the crawling from the mailbox user list. At that time, in order to catch up with the progress, I didn't study it in detail. I just found some information on the Internet and implemented the function. Now after organizing the original code, the function can still be used
Create a PHP file, copy the above code and save it. The effect will be immediate. Remember to change your email account and password. The account does not need the @ suffix. My first experience with CURL, how about it, not bad. Later, I saw someone posting on CSDN asking a question about getting express delivery queries. He wanted to put some large express delivery company query services on one page. It is indeed a very good and practical tool, but because express delivery queries have The verification code reminds me of the CURL tool. Later, I helped the post owner implement the function. The idea was very simple. First, use CURL to simulate grabbing the verification code, and then display it on the user submission page. At the same time, the COOKIE and other user queries that save the verification code are submitted together to ensure the synchronization of COOKIE.
The source code is as follows: -getEms.html
Copy code The code is as follows:
< ;html>
EMS Express Inquiry< /title>
fclose(fopen('cookie.txt','w')); //File cookie.txt Used to store the obtained cookie $cookiejar = realpath('cookie.txt'); $fp = fopen("example_homepage.txt", "w"); //The file example_homepage.txt is used to store the obtained cookie Page content $ch = curl_init("http://www.ems.com.cn/servlet/ImageCaptchaServlet"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ ch, CURLOPT_COOKIESESSION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp);
//readfile($cookiejar); //View the retrieved cookies / /readfile("example_homepage.jpg"); //View the retrieved pictures ?>
-getems.php
Copy code The code is as follows:
if($_POST){ //Use the cookie file of the previous verification code $cookiejar = realpath('cookie.txt'); //Get myEmsbarCode number and verification code variable name $ch = curl_init("http://www.ems.com.cn"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar); curl_setopt($ch, CURLOPT_CO OKIEJAR, $cookiejar); $result = curl_exec($ch); curl_close($ch); preg_match("//isU",$result,$myEmsbarCode); preg_match("/ $parm = array($codename[1]=>$_POST['code'], mailNum =>$_POST['mailNum'], myEmsbarCode=>$myEmsbarCode[1], reqCode=>'browseBASE' );
For a detailed explanation of the parameters of the CURL library, there are many on the Internet that I directly included Function list There are 17 functions in the CURL library: curl_close: close the CURL session curl_copy_handle: copy a CURL session handle, and at the same time 3 Copy all its parameters curl_errno: Return the last error code curl_error: Return a string to describe the last error of the current session curl_exec: Execute the current session curl_getinfo: Get specific information curl_init: Initialize CURL session curl_multi_add_handle: Add a handle to a multi-connection session curl_multi_close: Close a multi-handle CRUL session curl_multi_exec: Execute a multi-handle CURL session curl_multi_getcontent: Return The content after a handle is executed, if CURLOPT_RETURNTRANSFER is set curl_multi_info_read: Get information about all current connections curl_multi_init: Initialize a multi-handle session curl_multi_remove_handle: Remove a handle from a multi-handle session curl_multi_select : Get all bound sockets curl_setopt: Set CURL transmission options curl_version: Get CURL version Common setting options Boolean options CURLOPT_AUTOREFERER: When the returned information header contains redirection information, Automatically set forward connections CURLOPT_BINARYTRANSFER: TRUEtoreturntherawoutputwhenCURLOPT_RETURNTRANSFERisused. CURLOPT_COOKIESESSION: Flag for a new cookie session, ignore previously set cookie sessions CURLOPT_CRLF: Convert Unix system newlines to Dos newlines CURLOPT_DNS _USE_GLOBAL_CACHE : Use the global DNS cache CURLOPT_FAILONERROR: Ignore the returned error CURLOPT_FILETIME: Get the modification date of the requested document, which can be obtained with curl_getinfo(). CURLOPT_FOLLOWLOCATION: Follow all redirect information returned by the server CURLOPT_FORBID_REUSE: Force the session to be closed when the process is completed, and no longer cache it for reuse CURLOPT_FRESH_CONNECT: Force the establishment of a new session instead of reusing the cached one Session CURLOPT_HEADER: Include response header information in the returned output CURLOPT_HTTPGET: Set the HTTP request method to GET CURLOPT_HTTPPROXYTUNNEL: Establish a connection via an HTTP proxy CURLOPT_NOBODY: The returned output does not include document information . CURLOPT_NOPROGRESS: Disable process-level transmission, PHP automatically sets to true CURLOPT_NOSIGNAL: Ignore all information sent to PHP CURLOPT_POST: Set the POST method to submit data, the POST format is application/x-www-form- urlencoded CURLOPT_PUTTRUE: Set the PUT method to upload files, and set CURLOPT_INFILE and CURLOPT_INFILESIZE at the same time CURLOPT_RETURNTRANSFER: Return a string instead of directly outputting after calling curl_exec() CURLOPT_SSL_VERIFYPEER: SSL verification is turned on CURLOPT_UNRESTRIC TED_AUTH: always linked Append the username and password, and set CURLOPT_FOLLOWLOCATION CURLOPT_UPLOAD: Prepare to upload integer value options CURLOPT_BUFFERSIZE: Cache size CURLOPT_CONNECTTIMEOUT: Connection time setting, default 0 is unlimited CURLOPT_DNS_CACHE_TIMEOUT: Save DNS information in memory time, default 2 minutes CURLOPT_INFILESIZE: file size uploaded to the remote site CURLOPT_LOW_SPEED_LIMIT: minimum transmission speed limit andabort. CURLOPT_LOW_SPEED_TIME: transmission time limit CURLOPT_MAXCONNECTS: maximum number of persistent connections CURLOPT_MAXREDIRS : Maximum number of turns CURLOPT_PORT: Connection port CURLOPT_PROXYAUTH: ******Verification method CURLOPT_PROXYPORT: ******Port CURLOPT_PROXYTYPE: ******Type CURLOPT_TIMEOUT: Maximum execution time string option of CURL function CURLOPT_COOKIE: cookie information in set-cookie in HTTP header CURLOPT_COOKIEFILE: file containing cookie information. The format of cookie file can be Netscape format, or just HTTP header format. CURLOPT_COOKIEJAR: A file that saves cookie information after the connection is completed CURLOPT_CUSTOMREQUEST: Custom request header, using relative address CURLOPT_ENCODING: The value of Accept-Encoding in the HTTP request header CURLOPT_POSTFIELDS: Data submitted in POST format Content CURLOPT_PROXY: proxy channel CURLOPT_PROXYUSERPWD: proxy authentication username and password CURLOPT_RANGE: range of returned data, in bytes CURLOPT_REFERER: forward link CURLOPT_URL: URL address to connect to , can be set in curl_init() CURLOPT_USERAGENT: the value of User-Agent in the HTTP header CURLOPT_USERPWD: the verification information array option used for the connection CURLOPT_HTTP200ALIASES: 200 response code array, is the response in the array used? Considered a correct response CURLOPT_HTTPHEADER: Custom request header information can only be options for stream handles: CURLOPT_FILE: Transfer the evening handle to be written, the default is standard output CURLOPT_INFILE: Transfer the evening handle to be read File handle CURLOPT_STDERR: As a replacement option for standard error output CURLOPT_WRITEHEADER: The file callback function option to which the transfer header information is written CURLOPT_HEADERFUNCTION: A callback function with two parameters, the first parameter is The session handle, and the second is a string of HTTP response header information. Using this callback function, the response header information will be processed by itself. Response header information is returned line by line. Set the return value to the string length. CURLOPT_READFUNCTION: A callback function with two parameters. The first parameter is the session handle, and the second parameter is the string of HTTP response header information. Using this function, the returned data will be processed yourself. The return value is the data size. CURLOPT_WRITEFUNCTION: A callback function with two parameters. The first parameter is the session handle, and the second parameter is the string of HTTP response header information. Using this callback function, the response header information will be processed by itself. The response header information is the entire string. Set the return value to the string length. Some other CURL examples (excerpted from the Internet)
Copy code The code is as follows:
/* * Determine whether a url is a valid link */ function isRealUrl($url){ $ch = curl_init(); $options = array( CURLOPT_URL => $url, Curlopt_header = & GT; TRUE, Curlopt_returntransfer = & GT; TRUE, Curlopt_nobody = & GT; TRUE ); Curl_Setopt_ar ray ($ ch, $ options); Curl_exec ($ CH ); if(!curl_errno($ch)){ return 200==curl_getinfo($ch,CURLINFO_HTTP_CODE)?true:false; } curl_close($ch); }
// Upload files $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,'http://lh.tom.com/deal/import.php'); $fields = array( 'tname' => 'Tao Te Ching', 'country' => 1, 'author' => 'Lao Tzu', 'tags' => 'Tao Te Ching' , 'desc' => 'The Tao can be Tao, but it is very Tao. Famous, very famous. The beginning of the nameless world. Known as the mother of all things. Therefore, I always have no desire to observe its wonders. I always have the desire to watch him. The two have the same origin but different names, and they are both called xuan. Mysterious and mysterious, the door to all mysteries. ', 'volume' => 2, 'cover' => '@'.realpath('/data/lianhuanhua/deal/1.jpg') ); curl_setopt ($ch, CURLOPT_POST, true) ; curl_setopt($ch, CURLOPT_POSTFIELDS, $fields) ; curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); $result = curl_exec($ch); curl_close($ch);
When you master the php curl library, you can do a lot of things you want to do , Haha, I recently played the X world on Kaixin.com, and the combat was really cumbersome. I directly wrote a combat assistant that was very easy to use. This code will not be open sourced:) It can be implemented in open source just like mastering the principles. Website Counter
http://www.bkjia.com/PHPjc/327185.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327185.htmlTechArticleCURL can be said to be a must-have killer medicine for home travel. Why is it so described? It is because it is easy to use and can realize a series of functions such as page grabbing, simulated login collection and so on. I remember the first time I came into contact with CURL...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn