Zacznijmy kurs

CURL, Client URL Library Functions

XVIII. CURL, Client URL Library Functions

Wstęp

PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

These functions have been added in PHP 4.0.2.

Wymagania

In order to use PHP's cURL functions you need to install the libcurl package. PHP requires that you use libcurl 7.0.2-beta or higher. In PHP 4.2.3, you will need libcurl version 7.9.0 or higher. From PHP 4.3.0, you will need a libcurl version that's 7.9.8 or higher. PHP 5.0.0 requires a libcurl version 7.10.5 or greater.

Instalacja

To use PHP's cURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the "include" directory there should be a folder named "curl" which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the "lib" directory. Beginning with PHP 4.3.0 you can configure PHP to use cURL for URL streams --with-curlwrappers.

Note to Win32 Users: In order to enable this module on a Windows environment, libeay32.dll and ssleay32.dll must be present in your PATH.

You don't need libcurl.dll from the cURL site.

Stałe predefiniowane

Poniższe stałe są zdefiniowane w tym rozszerzeniu i stają się dostępne, gdy rozszerzenie jest dokompilowane do PHP, lub załadowane dynamicznie przy starcie.

CURLOPT_AUTOREFERER (integer)

Available since PHP 5.1.0

CURLOPT_COOKIESESSION (integer)

Available since PHP 5.1.0

CURLOPT_DNS_USE_GLOBAL_CACHE (integer)

CURLOPT_DNS_CACHE_TIMEOUT (integer)

CURLOPT_FTP_SSL (integer)

Available since PHP 5.2.0

CURLFTPSSL_TRY (integer)

Available since PHP 5.2.0

CURLFTPSSL_ALL (integer)

Available since PHP 5.2.0

CURLFTPSSL_CONTROL (integer)

Available since PHP 5.2.0

CURLFTPSSL_NONE (integer)

Available since PHP 5.2.0

CURLOPT_FTPSSLAUTH (integer)

Available since PHP 5.1.0

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_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_POSTFIELDS (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_COOKIE (integer)

CURLOPT_SSLCERT (integer)

CURLOPT_SSLCERTPASSWD (integer)

CURLOPT_WRITEHEADER (integer)

CURLOPT_SSL_VERIFYHOST (integer)

CURLOPT_COOKIEFILE (integer)

CURLOPT_SSLVERSION (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_SSL_VERIFYPEER (integer)

CURLOPT_CAINFO (integer)

CURLOPT_CAPATH (integer)

CURLOPT_COOKIEJAR (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_NTLM (integer)

CURLAUTH_ANY (integer)

CURLAUTH_ANYSAFE (integer)

CURLOPT_PROXYAUTH (integer)

CURLCLOSEPOLICY_LEAST_RECENTLY_USED (integer)

CURLCLOSEPOLICY_LEAST_TRAFFIC (integer)

CURLCLOSEPOLICY_SLOWEST (integer)

CURLCLOSEPOLICY_CALLBACK (integer)

CURLCLOSEPOLICY_OLDEST (integer)

CURLINFO_EFFECTIVE_URL (integer)

CURLINFO_HTTP_CODE (integer)

CURLINFO_HEADER_OUT (integer)

Available since PHP 6.0.0

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)

CURL_VERSION_IPV6 (integer)

CURL_VERSION_KERBEROS4 (integer)

CURL_VERSION_SSL (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_SHARE_IN_USE (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)

CURLFTPAUTH_DEFAULT (integer)

Available since PHP 5.1.0

CURLFTPAUTH_SSL (integer)

Available since PHP 5.1.0

CURLFTPAUTH_TLS (integer)

Available since PHP 5.1.0

CURLPROXY_HTTP (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)

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)

Przykłady

Once you've compiled PHP with cURL support, you can begin using the cURL functions. The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the cURL functions to fetch the example.com homepage into a file:

Przykład 1. Using PHP's cURL module to fetch the example.com homepage

<?php

$ch
= curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

Spis treści
curl_close -- Close a cURL session
curl_copy_handle -- Copy a cURL handle along with all of its preferences
curl_errno -- Return the last error number
curl_error -- Return a string containing the last error for the current session
curl_exec -- Perform a cURL session
curl_getinfo -- Get information regarding a specific transfer
curl_init -- Initialize a cURL session
curl_multi_add_handle -- Add a normal cURL handle to a cURL multi handle
curl_multi_close -- Close a set of cURL handles
curl_multi_exec -- Run the sub-connections of the current cURL handle
curl_multi_getcontent -- Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set
curl_multi_info_read -- Get information about the current transfers
curl_multi_init -- Returns a new cURL multi handle
curl_multi_remove_handle -- Remove a multi handle from a set of cURL handles
curl_multi_select -- Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array -- Set multiple options for a cURL transfer
curl_setopt -- Set an option for a cURL transfer
curl_version -- Gets cURL version information



WÄ…tki z forum o php

Najnowsze posty naszych userów

nie w³±cza sie ca³kowicie instalator systemu win xp.
witam, chcê mojej dziewczynie sformatowaæ komputer, po ustawieniu kolejno¶ci bootowania, resetuje komputer, wk³adam plyte z windowsem, i pojawia sie czarny ekran z informacja, ze wlacza sie instalator windows, potem pojawia sie niebeiski ekran z napisem instalator rozpakowywuje pliki i wtym momencie komputer staje, dysk przestaje sie krecic i naped tez, cos jakby zawieszka, dzieje sie to zarowno w przypadku winxp 1 wer. jak i ta z sp2. prosze o pomoc,

plyta glowna ECS, proc. Athlon 1GHz.
dual layer czy Double layer
Witam


Patrzê w everest jakie p³yty obs³uguje moja nagrywarka dvd.I przy jednej opcji pisze DVD+R9 Dual Layer czym¶ siê rózni od duble layer?I czy mogê kupiæ p³ytki duble layer aby je nagraæ? czy musz± byæ dual layer



Kaszanka dobra do wszystkiego [+18]
Drogie Bravo, drodzy koledzy i kole¿anki.Mam na imiê Dagmara i mam 19 lat. Moja sytuacja jest bardzo krepuj±ca i nie wiem co teraz mam zrobiæ. Jestem ju¿ doros³± dziewczyn± i mam wspania³ego ch³opaka o imieniu Marcin, którego kocham ponad ¿ycie i my¶lê ze on odwzajemnia moje uczucie. Jeste¶my ju¿ razem 6 miesiêcy i postanowili¶my dokonaæ Aktu Mi³osnego, aby umocniæ nasz zwi±zek. Nie fart polega na tym ¿e ja jestem dziewic±, a z tego co wiem On jest ju¿ do¶wiadczonym mê¿czyzn±. Bardzo obawia³am siê ¿e nie spe³niê jego oczekiwa , po prostu zawiodê! Na dodatek wszystkie moje kole¿anki potraci³y ju¿ dziewictwo i ¿eby mieæ o czym rozmawiaæ z nimi, powiedzia³am ¿e ja równie¿ nie jestem jak to siê mówi potocznie "cnotk±". O tym fakcie dowiedzia³ siê Marcin od mojej kole¿anki, Moniki, która jest jego dobr± znajom±. Gdy Marcin zapyta³ czy to prawda nie zaprzeczy³am. Ustalili¶my nasz Pierwszy Raz na najbli¿szy weekend, poniewa¿ Marcina rodzice jad± na wesele. Bardzo siê obawia³am bólu, oraz tego ¿e Marcin pos±dzi mnie o k³amstwo, wiêc postanowi³am jako¶ sobie poradziæ. Nie chcia³am przespaæ siê z "pierwszym lepszym" gdy¿ kocham Marcina i chcê aby to on by³ moim Pierwszym Mê¿czyzn±!! Akurat zdarzy³o siê tak ¿e by³am sama w domu i postanowi³am uporaæ siê z moja b³ona dziewicz±. Nie chcia³am robiæ tego palcami ani jakim¶ twardym przedmiotem a na wibrator niestety nie by³o by mnie staæ. Posz³am wiêc do lodówki i zobaczy³am nadaj±c± siê do mojego czynu kaszankê. Odpowiada³a mi rozmiarem i grubo¶ci±, by³a trochê za zimna i za twarda wiêc postanowi³am ja podgotowaæ. Kiedy nareszcie ostyg³a, nasmarowa³am ja wazelin±, i zaczê³am wk³adaæ j± do pochwy. Podda³am siê chyba za bardzo chwili i za bardzo j± ¶cisnê³am. Wtedy sta³o siê najgorsze co mog³o siê staæ!! KASZANKA SIÊ Z£AMA£A!!!!!!!!!!Rozpaczliwie próbowa³am j± wyj±æ palcami ale chyba trochê za bardzo j± rozgotowa³am i niektóre kawa³ki kaszanki zosta³y mi w pochwie i nie mogê ich wyj±æ! Wstydzê siê i¶æ do ginekologa a za kilka dni wyczekiwany przez nasz± dwójkê upojny weekend!! Nie wiem co mam zrobiæ i do kogo siê zwróciæ. Co teraz pomy¶li o mnie Marcin!! B£AGAM POMÓ¯CIE!!!!!
Zrozpaczona

Odpowied¼ Bravo:
Na wstêpie pragniemy podziêkowaæ Ci za podzielenie siê z nami swoim problemem. W twojej nader ciekawej sytuacji proponujemy Ci dwa rozwi±zania:
1. Ekstrawaganckie w stylu new art.
2. Si³owe

Pierwsze wydaje nam siê ciekawe lecz mo¿e nie przynie¶æ spodziewanych efektów. Musisz pokroiæ cebulê w kostkê, a nastêpnie podsma¿yæ j± na z³ocisty kolor na patelni (koniecznie na oleju z pierwszego tloczenia). Nastêpnie musisz dopchaæ j± do pochwy i zrobiæ 3-4 przysiadów tak aby zmiesza³a siê z kaszank±. Potem zapro¶ swojego ukochanego na romantyczne spotkanie inicjuj±ce. Przed pierwszym stosunkiem zaproponujesz mu wiêc kaszankê po staropolsku w wersji francuskiej. W ten sposób osi±gniesz dwa cele: udowodnisz mu, ¿e bardzo go kochasz i jednocze¶nie poka¿esz, ¿e ¶wietnie gotujesz. Przypominamy Ci powiedzenie "PRZEZ ¯O£¡DEK DO SERCA".

Rozwi±zanie drugie jest jednak o wiele bardziej skuteczne. Przygotuj patelniê na której mia³a¶ zarumieniæ cebulkê. Nastêpnie we¼ j± w praw± rêkê (je¶li jeste¶ leworêczna to w lew±) i [beeep]nij siê ni± z ca³ej si³y w g³owê - bo tobie to ju¿ chyba nic nie pomo¿e!
Z powa¿aniem Redakcja


Problemem bylo to, ze autor nie pozostawil mozliwosci zmian, wiec za pomoca programu PHP WebPage Editor zmienilem pewne potrzebne mi wartosci (ilosci wojsk - to akurat bylo latwe do znalezienia...), ale nie wiem, ktore wartosci odpowiadaja za czas wysylania tych jednostek wojska - chce zmienic z tych kilkunastu sekud na ok 1,5 godz... (to dziwne, bo nie jest to regularne - niektore ataki wychodza co 10 sek, niektore co 15 albo 20.