SlideShare a Scribd company logo
The PHP Client URL (cURL) library
Fulvio Corno
e-lite Research Group
Dipartimento di Automatica e Informatica
Politecnico di Torino
Torino - Italy
http://elite.polito.it
v. 1.0, 2009-03-23
The cURL library License
Outline
1 The cURL library
2 / 13
The PHP Client URL (cURL) library
The cURL library License
The problem
From a PHP page, being able to retrieve information served by
another web server
The information must be processed by the PHP page, not simply
shown on the resulting page
We need an synchronous remote call mechanism
3 / 13
The PHP Client URL (cURL) library
The cURL library License
Ingredients
1 The URL address of a remote web page
2 The parameters that we should pass to such remote page
How many parameters? Names? Data types? Values?
In what form? GET? POST? Encoding?
3 The format of the results returned by the remote page
Format: text? xml?
DTD or schema?
Error codes: in http response header or encoded as part of the
result?
4 / 13
The PHP Client URL (cURL) library
The cURL library License
The cURL library
cURL is one of the most powerful PHP extensions. It stands for
Client URL, and allows you to communicate with other servers
using a wide range of protocols.
libcurl (the library behind the PHP cURL extension) currently
supports a wide range of protocols, including HTTP, HTTPS,
FTP, TELNET, FILE, LDAP, DICT, GOPHER and HTTPS, as well
as HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading,
HTTP form based upload, proxies, cookies, and user:password
authentication.
5 / 13
The PHP Client URL (cURL) library
The cURL library License
Main functions
curl_init Initialize a cURL session – returns a “handle”
object ($ch)
curl_setopt Set an option for a cURL transfer – common
options: URL, POST data, result disposition
curl_exec Perform a cURL session – actual data transfer and
http request
curl_close Close a cURL session – end of transaction
6 / 13
The PHP Client URL (cURL) library
The cURL library License
Basic example
$ch = curl_init( ) ;
curl_setopt($ch, CURLOPT_URL, "http://abc.com/page.php") ;
// do a POST
curl_setopt($ch, CURLOPT_POST, true) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, "id=333") ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ) ;
// return the result of curl_exec, instead
// of outputting it directly
$result = curl_exec($ch) ;
curl_close($ch) ;
7 / 13
The PHP Client URL (cURL) library
The cURL library License
Sending the request
set the URL with CURLOPT_URL
parameters in GET
encoded in the URL
"...page.php?id=333&user=pippo"
parameters in POST
specify POST instead of GET with option CURLOPT_POST set to
true
specify all parameters in CURLOPT_POSTFIELDS
encoded as a string
as an associative array in PHP
8 / 13
The PHP Client URL (cURL) library
The cURL library License
Getting the result
call curl_exec($ch)
usually, the result is directly interpolated in the page (implicit
echo)
to avoid interpolation, set CURLOPT_RETURNTRANSFER to true
result is returned as a string by the curl_exec call
9 / 13
The PHP Client URL (cURL) library
The cURL library License
Other functions
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_getinfo Get information regarding a specific transfer
curl_setopt_array Set multiple options for a cURL transfer
curl_version Gets cURL version information
10 / 13
The PHP Client URL (cURL) library
The cURL library License
Other options
CURLOPT_HEADER TRUE to include the header in the output
CURLOPT_PORT An alternative port number to connect to.
CURLOPT_HTTPHEADER An array of HTTP header fields to
set.
CURLOPT_FILE The file that the transfer should be written to.
The default is STDOUT (the browser window).
11 / 13
The PHP Client URL (cURL) library
The cURL library License
Further information
http://www.php.net/manual/en/book.curl.php
12 / 13
The PHP Client URL (cURL) library
The cURL library License
License
This document is lincensed under the Creative Commons
Attribution-Noncommercial-Share Alike 3.0 Unported License.
http://creativecommons.org/licenses/by-nc-sa/3.0/
13 / 13
The PHP Client URL (cURL) library

More Related Content

PDF
Overloading Perl OPs using XS
ℕicolas ℝ.
 
DOC
Use perl creating web services with xml rpc
Johnny Pork
 
PPT
python-message-0.1.0
勇浩 赖
 
PDF
Scapy
Mohamed Gamel
 
PDF
Tcpdump
Mohamed Gamel
 
PPTX
Network configuration
engshemachi
 
PPTX
#2 (UDP)
Ghadeer AlHasan
 
Overloading Perl OPs using XS
ℕicolas ℝ.
 
Use perl creating web services with xml rpc
Johnny Pork
 
python-message-0.1.0
勇浩 赖
 
Tcpdump
Mohamed Gamel
 
Network configuration
engshemachi
 
#2 (UDP)
Ghadeer AlHasan
 

What's hot (19)

PPTX
Linux comands for Hadoop
PM Venkatesha Babu
 
DOC
socket programming
prashantzagade
 
PPT
Application Layer and Socket Programming
elliando dias
 
KEY
skipfish
Christian Heinrich
 
PDF
Introduction to tcpdump
Lev Walkin
 
PDF
บทที่ 2 โพรโตคอล (protocol)
chrisman77
 
PDF
2. reverse primarydns using bind for ptr and cname record ipv4
Piyush Kumar
 
PDF
Maksim Melnikau aka “max_posedon” - Telepathy protocol example
Minsk Linux User Group
 
PPTX
Basics of sockets
AviNash ChaVhan
 
PDF
Java sockets
Stephen Pradeep
 
PPT
Basic socket programming
Kristian Arjianto
 
PDF
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
Mohammad Reza Kamalifard
 
PDF
Network programming Using Python
Karim Sonbol
 
PPT
Iss letcure 7_8
Ali Habeeb
 
PDF
Socket Programming
elliando dias
 
PDF
Nodejs 프로그래밍 ch.3
HyeonSeok Choi
 
ODP
libpcap
mohan43u
 
PDF
Network Sockets
Peter R. Egli
 
PPT
Networking & Socket Programming In Java
Ankur Agrawal
 
Linux comands for Hadoop
PM Venkatesha Babu
 
socket programming
prashantzagade
 
Application Layer and Socket Programming
elliando dias
 
Introduction to tcpdump
Lev Walkin
 
บทที่ 2 โพรโตคอล (protocol)
chrisman77
 
2. reverse primarydns using bind for ptr and cname record ipv4
Piyush Kumar
 
Maksim Melnikau aka “max_posedon” - Telepathy protocol example
Minsk Linux User Group
 
Basics of sockets
AviNash ChaVhan
 
Java sockets
Stephen Pradeep
 
Basic socket programming
Kristian Arjianto
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
Mohammad Reza Kamalifard
 
Network programming Using Python
Karim Sonbol
 
Iss letcure 7_8
Ali Habeeb
 
Socket Programming
elliando dias
 
Nodejs 프로그래밍 ch.3
HyeonSeok Choi
 
libpcap
mohan43u
 
Network Sockets
Peter R. Egli
 
Networking & Socket Programming In Java
Ankur Agrawal
 
Ad

Similar to Php client libray (20)

PDF
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdf
ShaimaaMohamedGalal
 
PDF
Consuming RESTful services in PHP
Zoran Jeremic
 
PDF
Consuming RESTful Web services in PHP
Zoran Jeremic
 
PPTX
Curl Tutorial
Ankireddy Polu
 
PDF
Getting started with libcurl
Daniel Stenberg
 
PDF
mastering libcurl part 1
Daniel Stenberg
 
PPTX
Day01 api
ABDEL RAHMAN KARIM
 
ODP
Fscons scalable appplication transfers
Daniel Stenberg
 
PDF
Ilugc curl
Akilan Ram
 
PDF
Just curl it!
Daniel Stenberg
 
PDF
Internet all the things - curl everywhere!
Daniel Stenberg
 
PDF
curl better
Daniel Stenberg
 
PDF
mastering the curl command line.pdf
DanielStenberg7
 
PDF
Web services tutorial
Lorna Mitchell
 
PDF
PHP
kaushil shah
 
PDF
Php and-web-services-24402
PrinceGuru MS
 
PDF
The most exciting features of PHP 7.1
Zend by Rogue Wave Software
 
PDF
Tips
mclee
 
ODP
The promise of asynchronous php
Wim Godden
 
PDF
curl manual
Anthony Yuan , PMP
 
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdf
ShaimaaMohamedGalal
 
Consuming RESTful services in PHP
Zoran Jeremic
 
Consuming RESTful Web services in PHP
Zoran Jeremic
 
Curl Tutorial
Ankireddy Polu
 
Getting started with libcurl
Daniel Stenberg
 
mastering libcurl part 1
Daniel Stenberg
 
Fscons scalable appplication transfers
Daniel Stenberg
 
Ilugc curl
Akilan Ram
 
Just curl it!
Daniel Stenberg
 
Internet all the things - curl everywhere!
Daniel Stenberg
 
curl better
Daniel Stenberg
 
mastering the curl command line.pdf
DanielStenberg7
 
Web services tutorial
Lorna Mitchell
 
Php and-web-services-24402
PrinceGuru MS
 
The most exciting features of PHP 7.1
Zend by Rogue Wave Software
 
Tips
mclee
 
The promise of asynchronous php
Wim Godden
 
curl manual
Anthony Yuan , PMP
 
Ad

More from maamir farooq (20)

DOCX
Ooad lab1
maamir farooq
 
PPT
Lesson 03
maamir farooq
 
PPT
Lesson 02
maamir farooq
 
PDF
Swiftmailer
maamir farooq
 
PDF
Lect15
maamir farooq
 
PDF
Lec 7
maamir farooq
 
PPTX
Lec 6
maamir farooq
 
PDF
Lec 5
maamir farooq
 
PDF
J query 1.7 cheat sheet
maamir farooq
 
PDF
Assignment
maamir farooq
 
PDF
Java script summary
maamir farooq
 
PDF
Lec 3
maamir farooq
 
PDF
Lec 2
maamir farooq
 
PPTX
Lec 1
maamir farooq
 
PPTX
Css summary
maamir farooq
 
DOCX
Manual of image processing lab
maamir farooq
 
PDF
Session management
maamir farooq
 
PDF
Data management
maamir farooq
 
PPTX
Content provider
maamir farooq
 
PDF
Android sq lite database tutorial
maamir farooq
 
Ooad lab1
maamir farooq
 
Lesson 03
maamir farooq
 
Lesson 02
maamir farooq
 
Swiftmailer
maamir farooq
 
J query 1.7 cheat sheet
maamir farooq
 
Assignment
maamir farooq
 
Java script summary
maamir farooq
 
Css summary
maamir farooq
 
Manual of image processing lab
maamir farooq
 
Session management
maamir farooq
 
Data management
maamir farooq
 
Content provider
maamir farooq
 
Android sq lite database tutorial
maamir farooq
 

Recently uploaded (20)

PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Understanding operators in c language.pptx
auteharshil95
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 

Php client libray

  • 1. The PHP Client URL (cURL) library Fulvio Corno e-lite Research Group Dipartimento di Automatica e Informatica Politecnico di Torino Torino - Italy http://elite.polito.it v. 1.0, 2009-03-23
  • 2. The cURL library License Outline 1 The cURL library 2 / 13 The PHP Client URL (cURL) library
  • 3. The cURL library License The problem From a PHP page, being able to retrieve information served by another web server The information must be processed by the PHP page, not simply shown on the resulting page We need an synchronous remote call mechanism 3 / 13 The PHP Client URL (cURL) library
  • 4. The cURL library License Ingredients 1 The URL address of a remote web page 2 The parameters that we should pass to such remote page How many parameters? Names? Data types? Values? In what form? GET? POST? Encoding? 3 The format of the results returned by the remote page Format: text? xml? DTD or schema? Error codes: in http response header or encoded as part of the result? 4 / 13 The PHP Client URL (cURL) library
  • 5. The cURL library License The cURL library cURL is one of the most powerful PHP extensions. It stands for Client URL, and allows you to communicate with other servers using a wide range of protocols. libcurl (the library behind the PHP cURL extension) currently supports a wide range of protocols, including HTTP, HTTPS, FTP, TELNET, FILE, LDAP, DICT, GOPHER and HTTPS, as well as HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, and user:password authentication. 5 / 13 The PHP Client URL (cURL) library
  • 6. The cURL library License Main functions curl_init Initialize a cURL session – returns a “handle” object ($ch) curl_setopt Set an option for a cURL transfer – common options: URL, POST data, result disposition curl_exec Perform a cURL session – actual data transfer and http request curl_close Close a cURL session – end of transaction 6 / 13 The PHP Client URL (cURL) library
  • 7. The cURL library License Basic example $ch = curl_init( ) ; curl_setopt($ch, CURLOPT_URL, "http://abc.com/page.php") ; // do a POST curl_setopt($ch, CURLOPT_POST, true) ; curl_setopt($ch, CURLOPT_POSTFIELDS, "id=333") ; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ) ; // return the result of curl_exec, instead // of outputting it directly $result = curl_exec($ch) ; curl_close($ch) ; 7 / 13 The PHP Client URL (cURL) library
  • 8. The cURL library License Sending the request set the URL with CURLOPT_URL parameters in GET encoded in the URL "...page.php?id=333&user=pippo" parameters in POST specify POST instead of GET with option CURLOPT_POST set to true specify all parameters in CURLOPT_POSTFIELDS encoded as a string as an associative array in PHP 8 / 13 The PHP Client URL (cURL) library
  • 9. The cURL library License Getting the result call curl_exec($ch) usually, the result is directly interpolated in the page (implicit echo) to avoid interpolation, set CURLOPT_RETURNTRANSFER to true result is returned as a string by the curl_exec call 9 / 13 The PHP Client URL (cURL) library
  • 10. The cURL library License Other functions 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_getinfo Get information regarding a specific transfer curl_setopt_array Set multiple options for a cURL transfer curl_version Gets cURL version information 10 / 13 The PHP Client URL (cURL) library
  • 11. The cURL library License Other options CURLOPT_HEADER TRUE to include the header in the output CURLOPT_PORT An alternative port number to connect to. CURLOPT_HTTPHEADER An array of HTTP header fields to set. CURLOPT_FILE The file that the transfer should be written to. The default is STDOUT (the browser window). 11 / 13 The PHP Client URL (cURL) library
  • 12. The cURL library License Further information http://www.php.net/manual/en/book.curl.php 12 / 13 The PHP Client URL (cURL) library
  • 13. The cURL library License License This document is lincensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. http://creativecommons.org/licenses/by-nc-sa/3.0/ 13 / 13 The PHP Client URL (cURL) library