In PHP version 7.1.11 there is also constants for HTTP/2 :
CURL_VERSION_HTTP2 = 65536 (1 << 16)
CURL_HTTP_VERSION_2_0 = 3
I don't know the first version of PHP that defines it.
下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。
Descriptions and uses for these constants are described within the curl_setopt(), curl_multi_setopt() and curl_getinfo() documentation.
CURLOPT_AUTOREFERER
(integer)
CURLOPT_DNS_USE_GLOBAL_CACHE
(integer)
CURLOPT_DNS_CACHE_TIMEOUT
(integer)
CURLOPT_FTP_SSL
(integer)
CURLFTP_CREATE_DIR
(integer)
CURLFTP_CREATE_DIR_NONE
(integer)
CURLFTP_CREATE_DIR_RETRY
(integer)
CURLFTPSSL_TRY
(integer)
CURLFTPSSL_ALL
(integer)
CURLFTPSSL_CONTROL
(integer)
CURLFTPSSL_NONE
(integer)
CURLOPT_PRIVATE
(integer)
CURLOPT_FTPSSLAUTH
(integer)
CURLOPT_PORT
(integer)
CURLOPT_FILE
(integer)
CURLOPT_INFILE
(integer)
CURLOPT_INFILESIZE
(integer)
CURLOPT_URL
(integer)
CURLOPT_PROXY
(integer)
CURLOPT_VERBOSE
(integer)
CURLOPT_HEADER
(integer)
CURLOPT_HTTPHEADER
(integer)
CURLOPT_NOPROGRESS
(integer)
CURLOPT_NOBODY
(integer)
CURLOPT_FAILONERROR
(integer)
CURLOPT_UPLOAD
(integer)
CURLOPT_POST
(integer)
CURLOPT_FTPLISTONLY
(integer)
CURLOPT_FTPAPPEND
(integer)
CURLOPT_FTP_CREATE_MISSING_DIRS
(integer)
CURLOPT_NETRC
(integer)
CURLOPT_FOLLOWLOCATION
(integer)
CURLOPT_FTPASCII
(integer)
CURLOPT_PUT
(integer)
CURLOPT_MUTE
(integer)
CURLOPT_USERPWD
(integer)
CURLOPT_PROXYUSERPWD
(integer)
CURLOPT_RANGE
(integer)
CURLOPT_TIMEOUT
(integer)
CURLOPT_TIMEOUT_MS
(integer)
CURLOPT_TCP_NODELAY
(integer)
CURLOPT_POSTFIELDS
(integer)
CURLOPT_PROGRESSFUNCTION
(integer)
CURLOPT_REFERER
(integer)
CURLOPT_USERAGENT
(integer)
CURLOPT_FTPPORT
(integer)
CURLOPT_FTP_USE_EPSV
(integer)
CURLOPT_LOW_SPEED_LIMIT
(integer)
CURLOPT_LOW_SPEED_TIME
(integer)
CURLOPT_RESUME_FROM
(integer)
CURLOPT_SSLCERT
(integer)
CURLOPT_SSLCERTPASSWD
(integer)
CURLOPT_WRITEHEADER
(integer)
CURLOPT_SSL_VERIFYHOST
(integer)
CURLOPT_SSLVERSION
(integer)
CURL_SSLVERSION_DEFAULT
(integer)
CURL_SSLVERSION_TLSv1
(integer)
CURL_SSLVERSION_SSLv2
(integer)
CURL_SSLVERSION_SSLv3
(integer)
CURL_SSLVERSION_TLSv1_0
(integer)
CURL_SSLVERSION_TLSv1_1
(integer)
CURL_SSLVERSION_TLSv1_2
(integer)
CURLOPT_TIMECONDITION
(integer)
CURLOPT_TIMEVALUE
(integer)
CURLOPT_CUSTOMREQUEST
(integer)
CURLOPT_STDERR
(integer)
CURLOPT_TRANSFERTEXT
(integer)
CURLOPT_RETURNTRANSFER
(integer)
CURLOPT_QUOTE
(integer)
CURLOPT_POSTQUOTE
(integer)
CURLOPT_INTERFACE
(integer)
CURLOPT_KRB4LEVEL
(integer)
CURLOPT_HTTPPROXYTUNNEL
(integer)
CURLOPT_FILETIME
(integer)
CURLOPT_WRITEFUNCTION
(integer)
CURLOPT_READFUNCTION
(integer)
CURLOPT_PASSWDFUNCTION
(integer)
CURLOPT_HEADERFUNCTION
(integer)
CURLOPT_MAXREDIRS
(integer)
CURLOPT_MAXCONNECTS
(integer)
CURLOPT_CLOSEPOLICY
(integer)
CURLOPT_FRESH_CONNECT
(integer)
CURLOPT_FORBID_REUSE
(integer)
CURLOPT_RANDOM_FILE
(integer)
CURLOPT_EGDSOCKET
(integer)
CURLOPT_CONNECTTIMEOUT
(integer)
CURLOPT_CONNECTTIMEOUT_MS
(integer)
CURLOPT_SSL_VERIFYPEER
(integer)
CURLOPT_CAINFO
(integer)
CURLOPT_CAPATH
(integer)
CURLOPT_SSL_CIPHER_LIST
(integer)
CURLOPT_BINARYTRANSFER
(integer)
CURLOPT_NOSIGNAL
(integer)
CURLOPT_PROXYTYPE
(integer)
CURLOPT_BUFFERSIZE
(integer)
CURLOPT_HTTPGET
(integer)
CURLOPT_HTTP_VERSION
(integer)
CURLOPT_SSLKEY
(integer)
CURLOPT_SSLKEYTYPE
(integer)
CURLOPT_SSLKEYPASSWD
(integer)
CURLOPT_SSLENGINE
(integer)
CURLOPT_SSLENGINE_DEFAULT
(integer)
CURLOPT_SSLCERTTYPE
(integer)
CURLOPT_CRLF
(integer)
CURLOPT_ENCODING
(integer)
CURLOPT_PROXYPORT
(integer)
CURLOPT_UNRESTRICTED_AUTH
(integer)
CURLOPT_FTP_USE_EPRT
(integer)
CURLOPT_HTTP200ALIASES
(integer)
CURLOPT_HTTPAUTH
(integer)
CURLAUTH_BASIC
(integer)
CURLAUTH_DIGEST
(integer)
CURLAUTH_GSSNEGOTIATE
(integer)
CURLAUTH_NEGOTIATE
(integer)
CURLAUTH_NTLM
(integer)
CURLAUTH_NTLM_WB
(integer)
CURLAUTH_ANY
(integer)
CURLAUTH_ANYSAFE
(integer)
CURLOPT_PROXYAUTH
(integer)
CURLOPT_MAX_RECV_SPEED_LARGE
(integer)
CURLOPT_MAX_SEND_SPEED_LARGE
(integer)
CURLOPT_HEADEROPT
(integer)
CURLOPT_PROXYHEADER
(integer)
CURLCLOSEPOLICY_LEAST_RECENTLY_USED
(integer)
CURLCLOSEPOLICY_LEAST_TRAFFIC
(integer)
CURLCLOSEPOLICY_SLOWEST
(integer)
CURLCLOSEPOLICY_CALLBACK
(integer)
CURLCLOSEPOLICY_OLDEST
(integer)
CURLINFO_PRIVATE
(integer)
CURLINFO_EFFECTIVE_URL
(integer)
CURLINFO_HTTP_CODE
(integer)
CURLINFO_HEADER_OUT
(integer)
CURLINFO_HEADER_SIZE
(integer)
CURLINFO_REQUEST_SIZE
(integer)
CURLINFO_TOTAL_TIME
(integer)
CURLINFO_NAMELOOKUP_TIME
(integer)
CURLINFO_CONNECT_TIME
(integer)
CURLINFO_PRETRANSFER_TIME
(integer)
CURLINFO_SIZE_UPLOAD
(integer)
CURLINFO_SIZE_DOWNLOAD
(integer)
CURLINFO_SPEED_DOWNLOAD
(integer)
CURLINFO_SPEED_UPLOAD
(integer)
CURLINFO_FILETIME
(integer)
CURLINFO_SSL_VERIFYRESULT
(integer)
CURLINFO_CONTENT_LENGTH_DOWNLOAD
(integer)
CURLINFO_CONTENT_LENGTH_UPLOAD
(integer)
CURLINFO_STARTTRANSFER_TIME
(integer)
CURLINFO_CONTENT_TYPE
(integer)
CURLINFO_REDIRECT_TIME
(integer)
CURLINFO_REDIRECT_COUNT
(integer)
CURLINFO_REDIRECT_URL
(string)
CURLINFO_PRIMARY_IP
(string)
CURLINFO_PRIMARY_PORT
(integer)
CURLINFO_LOCAL_IP
(string)
CURLINFO_LOCAL_PORT
(integer)
CURL_PUSH_OK
(integer)
CURL_PUSH_DENY
(integer)
CURL_REDIR_POST_301
(integer)
CURL_REDIR_POST_302
(integer)
CURL_REDIR_POST_303
(integer)
CURL_REDIR_POST_ALL
(integer)
CURL_TIMECOND_IFMODSINCE
(integer)
CURL_TIMECOND_IFUNMODSINCE
(integer)
CURL_TIMECOND_LASTMOD
(integer)
CURL_VERSION_IPV6
(integer)
CURL_VERSION_KERBEROS4
(integer)
CURL_VERSION_KERBEROS5
(integer)
CURL_VERSION_HTTP2
(integer)
CURL_VERSION_PSL
(integer)
CURL_VERSION_SSL
(integer)
CURL_VERSION_UNIX_SOCKETS
(integer)
CURL_VERSION_LIBZ
(integer)
CURLVERSION_NOW
(integer)
CURLE_OK
(integer)
CURLE_UNSUPPORTED_PROTOCOL
(integer)
CURLE_FAILED_INIT
(integer)
CURLE_URL_MALFORMAT
(integer)
CURLE_URL_MALFORMAT_USER
(integer)
CURLE_COULDNT_RESOLVE_PROXY
(integer)
CURLE_COULDNT_RESOLVE_HOST
(integer)
CURLE_COULDNT_CONNECT
(integer)
CURLE_FTP_WEIRD_SERVER_REPLY
(integer)
CURLE_FTP_ACCESS_DENIED
(integer)
CURLE_FTP_USER_PASSWORD_INCORRECT
(integer)
CURLE_FTP_WEIRD_PASS_REPLY
(integer)
CURLE_FTP_WEIRD_USER_REPLY
(integer)
CURLE_FTP_WEIRD_PASV_REPLY
(integer)
CURLE_FTP_WEIRD_227_FORMAT
(integer)
CURLE_FTP_CANT_GET_HOST
(integer)
CURLE_FTP_CANT_RECONNECT
(integer)
CURLE_FTP_COULDNT_SET_BINARY
(integer)
CURLE_PARTIAL_FILE
(integer)
CURLE_FTP_COULDNT_RETR_FILE
(integer)
CURLE_FTP_WRITE_ERROR
(integer)
CURLE_FTP_QUOTE_ERROR
(integer)
CURLE_HTTP_NOT_FOUND
(integer)
CURLE_WRITE_ERROR
(integer)
CURLE_MALFORMAT_USER
(integer)
CURLE_FTP_COULDNT_STOR_FILE
(integer)
CURLE_READ_ERROR
(integer)
CURLE_OUT_OF_MEMORY
(integer)
CURLE_OPERATION_TIMEOUTED
(integer)
CURLE_FTP_COULDNT_SET_ASCII
(integer)
CURLE_FTP_PORT_FAILED
(integer)
CURLE_FTP_COULDNT_USE_REST
(integer)
CURLE_FTP_COULDNT_GET_SIZE
(integer)
CURLE_HTTP_RANGE_ERROR
(integer)
CURLE_HTTP_POST_ERROR
(integer)
CURLE_SSL_CONNECT_ERROR
(integer)
CURLE_FTP_BAD_DOWNLOAD_RESUME
(integer)
CURLE_FILE_COULDNT_READ_FILE
(integer)
CURLE_LDAP_CANNOT_BIND
(integer)
CURLE_LDAP_SEARCH_FAILED
(integer)
CURLE_LIBRARY_NOT_FOUND
(integer)
CURLE_FUNCTION_NOT_FOUND
(integer)
CURLE_ABORTED_BY_CALLBACK
(integer)
CURLE_BAD_FUNCTION_ARGUMENT
(integer)
CURLE_BAD_CALLING_ORDER
(integer)
CURLE_HTTP_PORT_FAILED
(integer)
CURLE_BAD_PASSWORD_ENTERED
(integer)
CURLE_TOO_MANY_REDIRECTS
(integer)
CURLE_UNKNOWN_TELNET_OPTION
(integer)
CURLE_TELNET_OPTION_SYNTAX
(integer)
CURLE_OBSOLETE
(integer)
CURLE_SSL_PEER_CERTIFICATE
(integer)
CURLE_GOT_NOTHING
(integer)
CURLE_SSL_ENGINE_NOTFOUND
(integer)
CURLE_SSL_ENGINE_SETFAILED
(integer)
CURLE_SEND_ERROR
(integer)
CURLE_RECV_ERROR
(integer)
CURLE_SSL_CERTPROBLEM
(integer)
CURLE_SSL_CIPHER
(integer)
CURLE_SSL_CACERT
(integer)
CURLE_BAD_CONTENT_ENCODING
(integer)
CURLE_LDAP_INVALID_URL
(integer)
CURLE_FILESIZE_EXCEEDED
(integer)
CURLE_FTP_SSL_FAILED
(integer)
CURLE_SSH
(integer)
CURLFTPAUTH_DEFAULT
(integer)
CURLFTPAUTH_SSL
(integer)
CURLFTPAUTH_TLS
(integer)
CURLPROXY_HTTP
(integer)
CURLPROXY_HTTP_1_0
(integer)
CURLPROXY_SOCKS4
(integer)
CURLPROXY_SOCKS5
(integer)
CURL_NETRC_OPTIONAL
(integer)
CURL_NETRC_IGNORED
(integer)
CURL_NETRC_REQUIRED
(integer)
CURL_HTTP_VERSION_NONE
(integer)
CURL_HTTP_VERSION_1_0
(integer)
CURL_HTTP_VERSION_1_1
(integer)
CURL_HTTP_VERSION_2
(integer)
CURL_HTTP_VERSION_2TLS
(integer)
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
(integer)
CURLM_CALL_MULTI_PERFORM
(integer)
CURLM_OK
(integer)
CURLM_BAD_HANDLE
(integer)
CURLM_BAD_EASY_HANDLE
(integer)
CURLM_OUT_OF_MEMORY
(integer)
CURLM_INTERNAL_ERROR
(integer)
CURLMSG_DONE
(integer)
CURLOPT_KEYPASSWD
(integer)
CURLOPT_SSH_AUTH_TYPES
(integer)
CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
(integer)
CURLOPT_SSH_PRIVATE_KEYFILE
(integer)
CURLOPT_SSH_PUBLIC_KEYFILE
(integer)
CURLOPT_SSL_OPTIONS
(integer)
CURLSSLOPT_ALLOW_BEAST
(integer)
CURLSSLOPT_NO_REVOKE
(integer)
CURLOPT_USERNAME
(integer)
CURLOPT_SASL_IR
(integer)
CURLOPT_DNS_INTERFACE
(integer)
CURLOPT_DNS_LOCAL_IP4
(integer)
CURLOPT_DNS_LOCAL_IP6
(integer)
CURLOPT_XOAUTH2_BEARER
(integer)
CURLOPT_LOGIN_OPTIONS
(integer)
CURLOPT_EXPECT_100_TIMEOUT_MS
(integer)
CURLOPT_SSL_ENABLE_ALPN
(integer)
CURLOPT_SSL_ENABLE_NPN
(integer)
CURLOPT_PINNEDPUBLICKEY
(integer)
CURLOPT_UNIX_SOCKET_PATH
(integer)
CURLOPT_SSL_VERIFYSTATUS
(integer)
CURLOPT_PATH_AS_IS
(integer)
CURLOPT_SSL_FALSESTART
(integer)
CURLOPT_PIPEWAIT
(integer)
CURLOPT_PROXY_SERVICE_NAME
(integer)
CURLOPT_SERVICE_NAME
(integer)
CURLOPT_DEFAULT_PROTOCOL
(integer)
CURLOPT_STREAM_WEIGHT
(integer)
CURLOPT_TFTP_NO_OPTIONS
(integer)
CURLOPT_CONNECT_TO
(integer)
CURLOPT_TCP_FASTOPEN
(integer)
CURLMOPT_PIPELINING
(integer)
CURLMOPT_MAXCONNECTS
(integer)
CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE
(integer)
CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE
(integer)
CURLMOPT_MAX_HOST_CONNECTIONS
(integer)
CURLMOPT_MAX_PIPELINE_LENGTH
(integer)
CURLMOPT_MAX_TOTAL_CONNECTIONS
(integer)
CURLMOPT_PUSHFUNCTION
(integer)
CURLSSH_AUTH_AGENT
(integer)
CURLSSH_AUTH_ANY
(integer)
CURLSSH_AUTH_DEFAULT
(integer)
CURLSSH_AUTH_HOST
(integer)
CURLSSH_AUTH_KEYBOARD
(integer)
CURLSSH_AUTH_NONE
(integer)
CURLSSH_AUTH_PASSWORD
(integer)
CURLSSH_AUTH_PUBLICKEY
(integer)
CURL_WRAPPERS_ENABLED
(integer)
CURLPAUSE_ALL
(integer)
CURLPAUSE_CONT
(integer)
CURLPAUSE_RECV
(integer)
CURLPAUSE_RECV_CONT
(integer)
CURLPAUSE_SEND
(integer)
CURLPAUSE_SEND_CONT
(integer)
CURLPIPE_NOTHING
(integer)
CURLPIPE_HTTP1
(integer)
CURLPIPE_MULTIPLEX
(integer)
CURLPROXY_SOCKS4A
(integer)
CURLPROXY_SOCKS5_HOSTNAME
(integer)
CURLHEADER_SEPARATE
(integer)
CURLHEADER_UNIFIED
(integer)
CURLPROTO_SMB
(integer)
CURLPROTO_SMBS
(integer)
In PHP version 7.1.11 there is also constants for HTTP/2 :
CURL_VERSION_HTTP2 = 65536 (1 << 16)
CURL_HTTP_VERSION_2_0 = 3
I don't know the first version of PHP that defines it.
Regarding CURLE_OPERATION_TIMEDOUT vs. CURLE_OPERATION_TIMEOUTED:
Originally cURL had the constant named TIMEOUTED (read: "timeout-ed"). This was changed[1] in 2007 and v7.17.0 to be TIMEDOUT (read: "timed out") and the old constant kept in place as an alias.
PHP started off using TIMEOUTED as well. The TIMEDOUT constant was added[2] in 2012 and v5.5.0 and the old constant was *kept in place*.
If you ask me, the TIMEDOUT constant reads more nicely (not to mention is technically the correct one to use) and as long as you're using PHP 5.5+ then it is available. If you have to support older versions then I suggest you keep using the new constant and add a polyfill like
<?php
if (version_compare(PHP_VERSION, "5.5.0", "<")) {
define("CURLE_OPERATION_TIMEDOUT", CURLE_OPERATION_TIMEOUTED);
}
?>
or
<?php
// PHP <5.5.0
defined("CURLE_OPERATION_TIMEDOUT") || define("CURLE_OPERATION_TIMEDOUT", CURLE_OPERATION_TIMEOUTED);
?>
to be removed once you stop supporting them.
[1] https://github.com/bagder/curl/commit/9f44a95522162c0f4a61093efe1bf1f58b087358#diff-d8c6cb80505e0f7d5e27fca2a682aa34L119
[2] https://github.com/php/php-src/commit/9ab45d3edbafa3ee751472c3f8d1fb3f51f38cf1#diff-ac978e3de205f1d14eb960e0eb15ef24R723
I hope this would be useful to convert error codes:
<?php
$curl_errno = array(
1 => "CURLE_UNSUPPORTED_PROTOCOL",
2 => "CURLE_FAILED_INIT",
3 => "CURLE_URL_MALFORMAT",
4 => "CURLE_URL_MALFORMAT_USER",
5 => "CURLE_COULDNT_RESOLVE_PROXY",
6 => "CURLE_COULDNT_RESOLVE_HOST",
7 => "CURLE_COULDNT_CONNECT",
8 => "CURLE_FTP_WEIRD_SERVER_REPLY",
9 => "CURLE_FTP_ACCESS_DENIED",
10 => "CURLE_FTP_USER_PASSWORD_INCORRECT",
11 => "CURLE_FTP_WEIRD_PASS_REPLY",
12 => "CURLE_FTP_WEIRD_USER_REPLY",
13 => "CURLE_FTP_WEIRD_PASV_REPLY",
14 => "CURLE_FTP_WEIRD_227_FORMAT",
15 => "CURLE_FTP_CANT_GET_HOST",
16 => "CURLE_FTP_CANT_RECONNECT",
17 => "CURLE_FTP_COULDNT_SET_BINARY",
18 => "CURLE_FTP_PARTIAL_FILE or CURLE_PARTIAL_FILE",
19 => "CURLE_FTP_COULDNT_RETR_FILE",
20 => "CURLE_FTP_WRITE_ERROR",
21 => "CURLE_FTP_QUOTE_ERROR",
22 => "CURLE_HTTP_NOT_FOUND or CURLE_HTTP_RETURNED_ERROR",
23 => "CURLE_WRITE_ERROR",
24 => "CURLE_MALFORMAT_USER",
25 => "CURLE_FTP_COULDNT_STOR_FILE",
26 => "CURLE_READ_ERROR",
27 => "CURLE_OUT_OF_MEMORY",
28 => "CURLE_OPERATION_TIMEDOUT or CURLE_OPERATION_TIMEOUTED",
29 => "CURLE_FTP_COULDNT_SET_ASCII",
30 => "CURLE_FTP_PORT_FAILED",
31 => "CURLE_FTP_COULDNT_USE_REST",
32 => "CURLE_FTP_COULDNT_GET_SIZE",
33 => "CURLE_HTTP_RANGE_ERROR",
34 => "CURLE_HTTP_POST_ERROR",
35 => "CURLE_SSL_CONNECT_ERROR",
36 => "CURLE_BAD_DOWNLOAD_RESUME or CURLE_FTP_BAD_DOWNLOAD_RESUME",
37 => "CURLE_FILE_COULDNT_READ_FILE",
38 => "CURLE_LDAP_CANNOT_BIND",
39 => "CURLE_LDAP_SEARCH_FAILED",
40 => "CURLE_LIBRARY_NOT_FOUND",
41 => "CURLE_FUNCTION_NOT_FOUND",
42 => "CURLE_ABORTED_BY_CALLBACK",
43 => "CURLE_BAD_FUNCTION_ARGUMENT",
44 => "CURLE_BAD_CALLING_ORDER",
45 => "CURLE_HTTP_PORT_FAILED",
46 => "CURLE_BAD_PASSWORD_ENTERED",
47 => "CURLE_TOO_MANY_REDIRECTS",
48 => "CURLE_UNKNOWN_TELNET_OPTION",
49 => "CURLE_TELNET_OPTION_SYNTAX",
50 => "CURLE_OBSOLETE",
51 => "CURLE_SSL_PEER_CERTIFICATE",
52 => "CURLE_GOT_NOTHING",
53 => "CURLE_SSL_ENGINE_NOTFOUND",
54 => "CURLE_SSL_ENGINE_SETFAILED",
55 => "CURLE_SEND_ERROR",
56 => "CURLE_RECV_ERROR",
57 => "CURLE_SHARE_IN_USE",
58 => "CURLE_SSL_CERTPROBLEM",
59 => "CURLE_SSL_CIPHER",
60 => "CURLE_SSL_CACERT",
61 => "CURLE_BAD_CONTENT_ENCODING",
62 => "CURLE_LDAP_INVALID_URL",
63 => "CURLE_FILESIZE_EXCEEDED",
64 => "CURLE_FTP_SSL_FAILED",
79 => "CURLE_SSH"
);
?>
Note that prior to PHP 5.5 following constants were missing and were available only through their numeric values:
CURL_SSLVERSION_DEFAULT // 0
CURL_SSLVERSION_TLSv1 // 1
CURL_SSLVERSION_SSLv2 // 2
CURL_SSLVERSION_SSLv3 // 3
This was fixed after this support request: https://bugs.php.net/bug.php?id=62318
Beware of CURLE_* constants!
On the official site:
http://curl.haxx.se/libcurl/c/libcurl-errors.html
some constants are different, some missing compared to the PHP implementation.
Some examples:
in PHP the curl error number 28 is called
CURLE_OPERATION_TIMEOUTED
while in the official site is:
CURLE_OPERATION_TIMEDOUT
So if you use the second, it won't march the error 28 because in PHP it is not defined that way.
The same is for these:
CURLE_HTTP_RETURNED_ERROR
CURLE_UPLOAD_FAILED
CURLE_INTERFACE_FAILED
CURLE_SSL_CERTPROBLEM
CURLE_SEND_FAIL_REWIND
CURLE_LOGIN_DENIED
CURLE_AGAIN
that are in someway named differently or missing from PHP.
<?
/*
* Author: Ron
* Released: August 4, 2007
* Description: An example of the disguise_curl() function in order to grab contents from a website while remaining fully camouflaged by using a fake user agent and fake headers.
*/
$url = 'http://www.ericgiguere.com/tools/http-header-viewer.html';
// disguises the curl using fake headers and a fake user agent.
function disguise_curl($url)
{
$curl = curl_init();
// Setup headers - I used the same headers from Firefox version 2.0.0.6
// below was split up because php.net said the line was too long. :/
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$html = curl_exec($curl); // execute the curl command
curl_close($curl); // close the connection
return $html; // and finally, return $html
}
// uses the function and displays the text off the website
$text = disguise_curl($url);
echo $text;
?>
~Ron