PHP development h5 chess and card source code curl usage (aqiulian.com), more PHPcurl usage consultation Q: 212303635. curl is a file transfer tool using URL syntax, supporting FTP, FTPS, HTTP HTTPS SCP SFTP TFTP TELNET DICT FILE and LDAP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploads, Kerberos, HTTP-based uploads, proxies, cookies, user+password authentication, file transfer recovery, http proxy channels and a host of other useful tricks. See the reference manual for details
It turns out that PHP does not extend this function by default, but it is still available, but it is not enabled. Open the PHP installation directory, search for the following three files ssleay32.dll, libeay32.dll and php_curl.dll, copy them one by one to the system32 folder in the system directory, modify the php.ini file, and find the line; extension= php_curl.dll. Remove the ; sign in front, save, and restart the server. Create a PHP file in the site directory with the following content
$ch = curl_init(“http://www.php.net”); curl_exec($ch); curl_close($ch);
Preview If you can open http://www.php.net, the installation is successful.
As for the installation of linux and unix, it may be a bit more troublesome. You have to download the curl library from http://curl.haxx.se/ or other websites.
The following are the following: Parameters used for each item of this function:
bool curl_setopt (int ch, string option, mixed value)
The curl_setopt() function will set options for a CURL session. The option parameter is the setting you want, and value is the value given by this option.
The values of the following options will be used as long integers (specified in the option parameter):
* CURLOPT_INFILESIZE: When you upload a file to the remote site, this option tells PHP that you The size of the uploaded file.
* CURLOPT_VERBOSE: If you want CURL to report every unexpected event, set this option to a non-zero value.
* CURLOPT_HEADER: If you want to include a header in the output, set this option to a non-zero value.
* CURLOPT_NOPROGRESS: If you do not want PHP to display a progress bar for CURL transfers, set this option to a non-zero value. Note: PHP automatically sets this option to a non-zero value, you should only change this option for debugging purposes.
* CURLOPT_NOBODY: If you do not want to include the body part in the output, set this option to a non-zero value.
* CURLOPT_FAILONERROR: If you want PHP not to display when an error occurs (HTTP code return greater than or equal to 300), set this option to a non-zero value. The default behavior is to return a normal page and ignore the code.
* CURLOPT_UPLOAD: If you want PHP to prepare for uploading, set this option to a non-zero value.
* CURLOPT_POST: If you want PHP to do a regular HTTP POST, set this option to a non-zero value. This POST is of the ordinary application/x-www-from-urlencoded type, mostly used by HTML forms.
* CURLOPT_FTPLISTONLY: Set this option to a non-zero value and PHP will list the directory names for FTP.
* CURLOPT_FTPAPPEND: Set this option to a non-zero value and PHP will apply the remote file instead of overwriting it.
* CURLOPT_NETRC: Set this option to a non-zero value and PHP will look in your ~./netrc file for the username and password of the remote site you want to connect to.
* CURLOPT_FOLLOWLOCATION: Set this option to a non-zero header (like "Location: ") and the server will send it as part of the HTTP header (note that this is recursive, PHP will send something like "Location: " head of).
* CURLOPT_PUT: Set this option to a non-zero value to upload a file using HTTP. To upload this file you must set the CURLOPT_INFILE and CURLOPT_INFILESIZE options.
* CURLOPT_MUTE: Set this option to a non-zero value and PHP will be completely silent for the CURL function.
* CURLOPT_TIMEOUT: Set a long integer as the maximum number of seconds.
* CURLOPT_LOW_SPEED_LIMIT: Set a long integer to control how many bytes are transmitted.
* CURLOPT_LOW_SPEED_TIME: Set a long integer to control how many seconds to transmit the number of bytes specified by CURLOPT_LOW_SPEED_LIMIT.
* CURLOPT_RESUME_FROM: Pass a long parameter containing the byte offset address (the start form you want to transfer to).
* CURLOPT_SSLVERSION: Pass a long parameter containing the SSL version. By default PHP will do its own hard work, in more security you have to set it manually.
* CURLOPT_TIMECONDITION: Pass a long parameter to specify how to handle the CURLOPT_TIMEVALUE parameter. You can set this parameter to TIMECOND_IFMODSINCE or TIMECOND_ISUNMODSINCE. This is only for HTTP.
* CURLOPT_TIMEVALUE: Pass a number of seconds from 1970-1-1 to now. This time will be used as the specified value by the CURLOPT_TIMEVALUE option, or by the default TIMECOND_IFMODSINCE.
The values of the following options will be treated as strings:
* CURLOPT_URL: 这是你想用PHP取回的URL地址。你也可以在用curl_init()函数初始化时设置这个选项。
* CURLOPT_USERPWD: 传递一个形如[username]:[password]风格的字符串,作用PHP去连接。
* CURLOPT_PROXYUSERPWD: 传递一个形如[username]:[password] 格式的字符串去连接HTTP代理。
* CURLOPT_RANGE: 传递一个你想指定的范围。它应该是”X-Y”格式,X或Y是被除外的。HTTP传送同样支持几个间隔,用逗句来分隔(X-Y,N-M)。
* CURLOPT_POSTFIELDS: 传递一个作为HTTP “POST”操作的所有数据的字符串。
* CURLOPT_REFERER: 在HTTP请求中包含一个”referer”头的字符串。
* CURLOPT_USERAGENT: 在HTTP请求中包含一个”user-agent”头的字符串。
* CURLOPT_FTPPORT: 传递一个包含被ftp “POST”指令使用的IP地址。这个POST指令告诉远程服务器去连接我们指定的IP地址。这个字符串可以是一个IP地址,一个主机名,一个网络界面名(在UNIX下),或是‘-’(使用系统默认IP地址)。
* CURLOPT_COOKIE: 传递一个包含HTTP cookie的头连接。
* CURLOPT_SSLCERT: 传递一个包含PEM格式证书的字符串。
* CURLOPT_SSLCERTPASSWD: 传递一个包含使用CURLOPT_SSLCERT证书必需的密码。
* CURLOPT_COOKIEFILE: 传递一个包含cookie数据的文件的名字的字符串。这个cookie文件可以是Netscape格式,或是堆存在文件中的HTTP风格的头。
* CURLOPT_CUSTOMREQUEST: 当进行HTTP请求时,传递一个字符被GET或HEAD使用。为进行DELETE或其它操作是有益的,更Pass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing or another, more obscure, HTTP request. 注意: 在确认你的服务器支持命令先不要去这样做。下列的选项要求一个文件描述(通过使用fopen()函数获得):
* CURLOPT_FILE: 这个文件将是你放置传送的输出文件,默认是STDOUT.
* CURLOPT_INFILE: 这个文件是你传送过来的输入文件。
* CURLOPT_WRITEHEADER: 这个文件写有你输出的头部分。
* CURLOPT_STDERR: 这个文件写有错误而不是stderr。用来获取需要登录的页面的例子,当前做法是每次或许都登录一次,有需要的人再做改进了.
摘几个从别的网站扣过来的例子:
例一:
$cookie_jar = tempnam(‘./tmp’,'cookie’); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, ‘http://******’); curl_setopt($ch, CURLOPT_POST, 1); $request = ‘email_address=&password=&action=’; curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //把返回来的cookie信息保存在$cookie_jar文件中 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar); //设定返回的数据是否自动显示 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设定是否显示头信息 curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容 curl_setopt($ch, CURLOPT_NOBODY, false); curl_exec($ch); curl_close($ch); //get data after login
例二:
$ch2 = curl_init();curl_setopt($ch2, CURLOPT_URL, ‘ curl_setopt($ch2, CURLOPT_HEADER, false);curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);$orders = curl_exec($ch2);echo ”; echo strip_tags($orders);echo ”;curl_close($ch2); 实践证明很稳定:)
例三:
set_time_limit(0); function _rand() { $length=26; $chars = “0123456789abcdefghijklmnopqrstuvwxyz”; $max = strlen($chars) – 1; mt_srand((double)microtime() * 1000000); $string = ”; for($i = 0; $i < $length; $i++) { $string .= $chars[mt_rand(0, $max)]; } return $string; } $HTTP_SESSION=_rand(); echo $HTTP_SESSION; $HTTP_Server="www.baidu.com"; $HTTP_URL="/"; $ch = curl_init(); curl_setopt ($ch,CURLOPT_URL,"http://".$HTTP_Server.$HTTP_URL); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"); //curl_setopt($ch,CURLOPT_COOKIE,$HTTP_SESSION); $res = curl_exec($ch); curl_close ($ch); print_r($res);
刷论坛代码:
1、抓cookies程序:
$URL="http://www.yoururl.com/bbs/login.asp?action=chk";//填入论坛的登陆页面地址$ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$URL); curl_setopt($ch,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/login.asp");//设置,访问页面的来源地址 curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_POSTFIELDS,'username=→→敢死队→&password=168168'); //分析登陆页面,把用户名,密码分别对应起来curl_setopt ($ch, CURLOPT_HEADER,true); //使能显示http头,curl_exec($ch);if (curl_errno($ch)){print curl_error($ch);}else{curl_close($ch);}
2、刷楼了:
set_time_limit(0);//设置程序执行时间无限制$i=10000;//耍10000次for($j=0;$j<$i;$j++){ $URL="http://www.yoururl.com/bbs/savepost.asp";//这个地址是回复表单里面action的url地址$ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$URL); curl_setopt($ch,CURLOPT_REFERER," //设置来源地址,如果不设置,论坛服务器有可能有验证不允许回复curl_setopt($ch,CURLOPT_COOKIESESSION,true); //能保存cookiecurl_setopt ($ch,CURLOPT_COOKIE,"DvForum=userid=24122&usercookies=0&userhidden=2&password=w0reu3g775VrY745&userclass=%96%7C&username=%A1%FA%A1 %FA%B8%D2%CB%C0%B6%D3%A1%FA&StatUserID=2194783945 ");//这儿就是设置cookie了curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_NOBODY,1); //不显示内容,因为有很多论坛回复后要自动跳转。curl_setopt($ch,CURLOPT_POSTFIELDS,'Body=gfdfgdfgasdfgdfgdfgdfg& followup=672709&RootID=1274 37&star=58&TotalUseTable=Dv_bbs3& amp;UserName=→→敢死队→&signflag=1&total=65535');//把你分析的回复表单的参数分别赋值curl_setopt ($ch, CURLOPT_ HEADER,true);curl_exec($ch);if (curl_errno($ch)){print curl_error($ch);}else{curl_close($ch);} }
curl_close — 关闭一个curl会话
curl_copy_handle — 拷贝一个curl连接资源的所有内容和参数
curl_errno — 返回一个包含当前会话错误信息的数字编号
curl_error — 返回一个包含当前会话错误信息的字符串
curl_exec — 执行一个curl会话
curl_getinfo — 获取一个curl连接资源句柄的信息
curl_init — 初始化一个curl会话
curl_multi_add_handle — 向curl批处理会话中添加单独的curl句柄资源
curl_multi_close — 关闭一个批处理句柄资源
curl_multi_exec — 解析一个curl批处理句柄
curl_multi_getcontent — 返回获取的输出的文本流
curl_multi_info_read — 获取当前解析的curl的相关传输信息
curl_multi_init — 初始化一个curl批处理句柄资源
curl_multi_remove_handle — 移除curl批处理句柄资源中的某个句柄资源
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — 以数组的形式为一个curl设置会话参数
curl_setopt — 为一个curl设置会话参数
curl_version — 获取curl相关的版本信息
curl_init()函数的作用初始化一个curl会话,curl_init()函数唯一的一个参数是可选的,表示一个url地址。
curl_exec()函数的作用是执行一个curl会话,唯一的参数是curl_init()函数返回的句柄。
curl_close()函数的作用是关闭一个curl会话,唯一的参数是curl_init()函数返回的句柄。
$ch = curl_init("http://www.baidu.com/");
curl_exec($ch);
curl_close($ch);
curl_version()函数的作用是获取curl相关的版本信息,curl_version()函数有一个参数,不清楚是做什么的
print_r(curl_version())
curl_getinfo()函数的作用是获取一个curl连接资源句柄的信息,curl_getinfo()函数有两个参数,第一个参数是curl的资源句柄,第二个参数是下面一些常量:
$ch = curl_init("http://www.baidu.com/");
print_r(curl_getinfo($ch));
可选的常量包括:
CURLINFO_EFFECTIVE_URL
最后一个有效的url地址
CURLINFO_HTTP_CODE
最后一个收到的HTTP代码
CURLINFO_FILETIME
远程获取文档的时间,如果无法获取,则返回值为“-1”
CURLINFO_TOTAL_TIME
Time spent on the last transfer
CURLINFO_NAMELOOKUP_TIME
Time spent on name resolution
CURLINFO_CONNECT_TIME
Time spent establishing a connection
CURLINFO_PRETRANSFER_TIME
The time it takes from establishing the connection to preparing the transmission
CURLINFO_STARTTRANSFER_TIME
The time it takes from establishing the connection to the beginning of the transmission
CURLINFO_REDIRECT_TIME
At the beginning of the transaction transmission Time taken before redirection
CURLINFO_SIZE_UPLOAD
Total value of uploaded data volume
CURLINFO_SIZE_DOWNLOAD
Total value of downloaded data volume
CURLINFO_SPEED_DOWNLOAD
Avg. Download speed
CURLINFO_SPEED_UPLOAD
Average upload speed
CURLINFO_HEADER_SIZE
The size of the header part
CURLINFO_HEADER_OUT
The string to send the request
CURLINFO_REQUEST_SIZE
The request size in question in the HTTP request
CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD
From the Content-Length: field Read download content length
CURLINFO_CONTENT_LENGTH_UPLOAD
Description of upload content size
CURLINFO_CONTENT_TYPE
The "Content-type" value of the downloaded content, NULL means that the server did not send a valid "Content -Type: header”
curl_setopt() function is used to set session parameters for a curl. The curl_setopt_array() function is used to set session parameters for a curl in the form of an array.
$ch = curl_init();
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
$ options = array(
CURLOPT_URL => 'http://www.baidu.com/',
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);
The parameters that can be set are:
CURLOPT_AUTOREFERER
Automatic setting Referer information in header
CURLOPT_BINARYTRANSFER
When CURLOPT_RETURNTRANSFER is enabled, the data will be obtained and returned
CURLOPT_COOKIESESSION
When enabled, curl will only pass one session cookie and ignore other cookies. The default condition is Next curl will return all cookies to the server. Session cookies refer to cookies that are used to determine whether the server-side session is valid.
CURLOPT_CRLF
When enabled, convert Unix line feed characters into carriage return and line feed characters.
CURLOPT_DNS_USE_GLOBAL_CACHE
When enabled, a global DNS cache is enabled. This item is thread-safe and defaults to true.
CURLOPT_FAILONERROR
Display HTTP status code, the default behavior is to ignore HTTP information with a number less than or equal to 400
CURLOPT_FILETIME
When enabled, it will try to modify the information in the remote document. The result information will be returned through the CURLINFO_FILETIME option of the curl_getinfo() function.
CURLOPT_FOLLOWLOCATION
When enabled, the "Location:" returned by the server will be placed in the header and returned to the server recursively. Use CURLOPT_MAXREDIRS to limit the number of recursive returns.
CURLOPT_FORBID_REUSE
Forcibly disconnect after completing the interaction and cannot be reused.
CURLOPT_FRESH_CONNECT
Force to obtain a new connection to replace the connection in the cache.
CURLOPT_FTP_USE_EPRT
TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.
Added in PHP 5.0.0.
CURLOPT_FTP_USE_EPSV
TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.
CURLOPT_FTPAPPEND
TRUE to append to the remote file instead of overwriting it .
CURLOPT_FTPASCII
An alias of CURLOPT_TRANSFERTEXT. Use that instead.
CURLOPT_FTPLISTONLY
TRUE to only list the names of an FTP directory.
CURLOPT_HEADER
When enabled, the header file information will be output as a data stream.
CURLOPT_HTTPGET
When enabled, the HTTP method will be set to GET. Because GET is the default, it is only used when it is modified.
CURLOPT_HTTPPROXYTUNNEL
When enabled, it will be transmitted through HTTP proxy.
CURLOPT_MUTE
Restore all modified parameters in the curl function to their default values.
CURLOPT_NETRC
After the connection is established, access the ~/.netrc file to obtain the username and password information to connect to the remote site.
CURLOPT_NOBODY
When enabled, the body part in HTML will not be output.
CURLOPT_NOPROGRESS
Close the progress bar of curl transmission when enabled. The default setting of this item is true
CURLOPT_NOSIGNAL
Ignore all signals passed by curl to PHP when enabled. This item is turned on by default during SAPI multi-thread transmission.
CURLOPT_POST
When enabled, a regular POST request will be sent, type: application/x-www-form-urlencoded, just like the form submission.
CURLOPT_PUT
When enabled, HTTP is allowed to send files. CURLOPT_INFILE and CURLOPT_INFILESIZE must be set at the same time.
CURLOPT_RETURNTRANSFER
The information obtained by curl_exec() is returned in the form of a file stream instead of directly output.
CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2). TRUE by default as of cURL 7.10. Default bundle installed as of cURL 7.10.
CURLOPT_TRANSFERTEXT
TRUE to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode.
CURLOPT_UNRESTRICTED_AUTH
Continuously append username and password information to multiple locations in the header generated using CURLOPT_FOLLOWLOCATION , even if the domain name has changed.
CURLOPT_UPLOAD
Allow file transfer when enabled
CURLOPT_VERBOSE
When enabled, all information will be reported and stored in STDERR or the specified CURLOPT_STDERR
CURLOPT_BUFFERSIZE
The size of the cache read into the data obtained each time, this value will be filled every time.
CURLOPT_CLOSEPOLICY
Either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST, there are three others, but curl does not support them yet. .
CURLOPT_CONNECTTIMEOUT
The time to wait before initiating a connection. If set to 0, there will be no waiting.
CURLOPT_DNS_CACHE_TIMEOUT
Set the time to save DNS information in memory, the default is 120 seconds.
CURLOPT_FTPSSLAUTH
The FTP authentication method (when is activated): CURLFTPAUTH_SSL (try SSL first), CURLFTPAUTH_TLS (try TLS first), or CURLFTPAUTH_DEFAULT (let cURL decide).
CURLOPT_HTTP_VERSION
Set the HTTP protocol used by curl, CURL_HTTP_VERSION_NONE (let curl decide by itself), CURL_HTTP_VERSION_1_0 (HTTP/1.0), CURL_HTTP_VERSION_1_1 (HTTP/1.1)
CURLOPT_HTTPAUTH
HTTP verification method used, optional value There are: CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, CURLAUTH_ANYSAFE. You can use the "|" operator to separate multiple values. curl lets the server choose the best supported value. CURLAUTH_ANY is equivalent to CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURL AUTH_NTLM,CURLAUTH_ANYSAFE Equivalent to CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
CURLOPT_INFILESIZE
Set the size of the uploaded file
CURLOPT_LOW_SPEED_LIMIT
When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT, PHP will determine whether it is too large based on CURLOPT_LOW_SPEED_TIME Slow and canceled transfer.
CURLOPT_LOW_SPEED_TIME
The number of seconds the transfer should be below CURLOPT_LOW_SPEED_LIMIT for PHP to consider the transfer too slow and abort. Slow and canceled transfer.
The maximum number of connections allowed, if exceeded, CURLOPT_CLOSEPOLICY will be used to determine which connections should be stopped
Specify the maximum number of HTTP redirects, this option is the same as CURLOPT_FOLLOWLOCATION used together.
An optional quantity used to specify the connection port
The HTTP authentication method(s) to use for the proxy connection. Use the same bitmasks as described in CURLOPT_HTTPAUTH. For proxy authentication, only CURLAUTH_BASIC and CURLAUTH_NTLM are currently supported.
The port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY.
Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.
Pass a byte offset when resuming the transfer (used for breakpoint resumption)
1 to check the existence of a common name in the SSL peer certificate.
2 to check the existence of a common name and also verify that it matches the hostname provided.
The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.
If after a certain time specified by CURLOPT_TIMEVALUE If it has been edited, CURL_TIMECOND_IFMODSINCE is used to return the page. If it has not been modified and CURLOPT_HEADER is true, a "304 Not Modified" header is returned. If CURLOPT_HEADER is false, CURL_TIMECOND_ISUNMODSINCE is used. The default value is CURL_TIMECOND_IFMODSINCE
Set the maximum number of seconds curl is allowed to execute
Set a timestamp used by CURLOPT_TIMECONDITION. In the default state, CURL_TIMECOND_IFMODSINCE
The name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with CURLOPT_SSL_VERIFYPEER.
A directory that holds multiple CA certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER.
Set the content of the "Set-Cookie:" part of the HTTP request.
CURLOPT_COOKIEFILE
The name of the file containing cookie information. This cookie file can be Netscape format or HTTP style header information.
CURLOPT_COOKIEJAR
After the connection is closed, the file name to store cookie information
CURLOPT_CUSTOMREQUEST
A custom request method to use instead of “GET” or “HEAD” when doing a HTTP request . This is useful for doing “DELETE” or other, more obscure HTTP requests. Valid values are things like “GET”, “POST”, “CONNECT” and so on; i.e. Do not enter a whole HTTP request line here. For instance , entering “GET /index.html HTTP/1.0\r\n\r\n” would be incorrect.
Note: Don't do this without making sure the server supports the custom request method first.
CURLOPT_EGBSOCKET
Like CURLOPT_RANDOM_FILE, except a filename to an Entropy Gathering Daemon socket.
CURLOPT_ENCODING
The contents of the "Accept-Encoding:" part of the header, the supported encoding format is: "identity" , "deflate", "gzip". If set to an empty string, it means that all encoding formats are supported
CURLOPT_FTPPORT
The value which will be used to get the IP address to use for the FTP “POST” instruction. The “POST” instruction tells the remote server to connect to our specified IP address. The string may be a plain IP address, a hostname, a network interface name (under Unix), or just a plain '-' to use the systems default IP address.
CURLOPT_INTERFACE
The name used in the external network interface, which can be an interface name, IP or host name.
CURLOPT_KRB4LEVEL
KRB4 (Kerberos 4) security level setting can be one of the following values: "clear", "safe", "confidential", "private". The default value is "private". When set to null, it means KRB4 is disabled. Now KRB4 security can only be used in FTP transmission.
CURLOPT_POSTFIELDS
The "POST" operation in HTTP. If you want to transfer a file, you need a file name starting with @
CURLOPT_PROXY
Set the HTTP proxy server passed
CURLOPT_PROXYUSERPWD
Connect to the proxy server, the format is "[username ]:[password]" username and password.
CURLOPT_RANDOM_FILE
Set the file name to store the random number seed used by SSL
CURLOPT_RANGE
Set the HTTP transmission range. You can set a transmission range in the form of "X-Y". If there are multiple HTTP transfers, use commas to separate multiple values, such as: "X-Y,N-M".
CURLOPT_REFERER
Set the value of the "Referer:" part in the header.
CURLOPT_SSL_CIPHER_LIST
A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.
CURLOPT_SSLCERT
Pass a character containing the PEM format certificate string.
CURLOPT_SSLCERTPASSWD
Pass a pass containing the password required to use the CURLOPT_SSLCERT certificate.
CURLOPT_SSLCERTTYPE
The format of the certificate. Supported formats are “PEM” (default), “DER”, and “ENG”.
CURLOPT_SSLENGINE
The identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY.
CURLOPT_SSLENGINE_DEFAULT
The identifier for the crypto engine used for asymmetric crypto operations.
CURLOPT_SSLKEY
The name of a file containing a private SSL key.
CURLOPT_SSLKEYPASSWD
The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY.
Note: Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.
CURLOPT_SSLKEYTYPE
The key type of the private SSL key specified in CURLOPT_SSLKEY. Supported key types are “PEM” (default), “DER”, and “ENG”.
CURLOPT_URL
The URL address to be obtained can also be set in PHP's curl_init() function.
CURLOPT_USERAGENT
Contains a "user-agent" header string in the HTTP request.
CURLOPT_USERPWD
Pass the username and password required for a connection, in the format: "[username]:[password]".
CURLOPT_HTTP200ALIASES
Set to no longer process HTTP 200 responses in the form of error, in the format of an array.
CURLOPT_HTTPHEADER
Set an array of transmission content in the header.
CURLOPT_POSTQUOTE
An array of FTP commands to execute on the server after the FTP request has been performed.
CURLOPT_QUOTE
An array of FTP commands to execute on the server prior to the FTP request.
CURLOPT_FILE
Set the location of the output file. The value is a resource type. The default is STDOUT (browser).
CURLOPT_INFILE
The file address that needs to be read when uploading a file, the value is a resource type.
CURLOPT_STDERR
Set an error output address, the value is a resource type, replacing the default STDERR.
CURLOPT_WRITEHEADER
Set the file address where the header part is written, and the value is a resource type.
CURLOPT_HEADERFUNCTION
Set a callback function. This function has two parameters. The first is the resource handle of curl, and the second is the output header data. The output of header data must rely on this function, which returns the size of the written data.
CURLOPT_PASSWDFUNCTION
Set a callback function with three parameters. The first is the curl resource handle, the second is a password prompt, and the third parameter is the maximum allowed password length. Returns the value of the password.
CURLOPT_READFUNCTION
Set a callback function with two parameters. The first is the resource handle of curl, and the second is the read data. Data reading must rely on this function. Returns the size of the read data, such as 0 or EOF.
CURLOPT_WRITEFUNCTION
Set a callback function with two parameters. The first is the resource handle of curl, and the second is the written data. Data writing must rely on this function. Return the exact size of the written data
The function of curl_copy_handle() is to copy all the contents and parameters of a curl connection resource
$ch = curl_init(“http://www. baidu.com/”);
$another = curl_copy_handle($ch);
curl_exec($another);
curl_close($another);
curl_error() function is Returns a string containing error information for the current session.
The function of curl_errno() function is to return a numeric number containing error information of the current session.
The curl_multi_init() function is used to initialize a curl batch handle resource.
The curl_multi_add_handle() function is used to add individual curl handle resources to the curl batch session. The curl_multi_add_handle() function has two parameters. The first parameter represents a curl batch handle resource, and the second parameter represents a single curl handle resource.
The function of the curl_multi_exec() function is to parse a curl batch handle. The curl_multi_exec() function has two parameters. The first parameter represents a batch handle resource, and the second parameter is a reference value parameter, indicating the remaining The number of individual curl handle resources that need to be processed.
The curl_multi_remove_handle() function represents the removal of a handle resource in the curl batch handle resource. The curl_multi_remove_handle() function has two parameters. The first parameter represents a curl batch handle resource, and the second parameter represents a separate The curl handle resource.
The curl_multi_close() function is used to close a batch handle resource.
$ch1 = curl_init();
$ch2 = curl_init();
curl_setopt($ch1, CURLOPT_URL, “http://www.baidu.com/”);
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, “http://www.google.com/”);
curl_setopt($ch2, CURLOPT_HEADER, 0);
$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
do {
curl_multi_exec($mh,$flag);
} while ($flag > 0);
curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_close($mh);
The function of curl_multi_getcontent() is to return the obtained output text stream when CURLOPT_RETURNTRANSFER is set.
The curl_multi_info_read() function is used to obtain the relevant transmission information of the currently parsed curl.
curl_multi_select()
Get all the sockets associated with the cURL extension, which can then be “selected”
source url:http://www.hebaodans.com /2009/07/p-h-p-c-u-r-l-yong-fa/
Related recommendations:
php Detailed explanation of data crawling curl example
Detailed explanation of PHP using CURL
The above is the detailed content of PHP development h5 source code curl usage example. For more information, please follow other related articles on the PHP Chinese website!