Tutorial by Examples

cURL is a tool for transferring data with URL syntax. It support HTTP, FTP, SCP and many others(curl >= 7.19.4). Remember, you need to install and enable the cURL extension to use it. // a little script check is the cURL extension loaded or not if(!extension_loaded("curl")) { die...
If you want to mimic HTML form POST action, you can use cURL. // POST data in array $post = [ 'a' => 'apple', 'b' => 'banana' ]; // Create a new cURL resource with URL to POST $ch = curl_init('http://www.example.com'); // We set parameter CURLOPT_RETURNTRANSFER to read outp...
Sometimes we need to make a lot of POST requests to one or many different endpoints. To deal with this scenario, we can use multi_curl. First of all, we create how many requests as needed exactly in the same way of the simple example and put them in an array. We use the curl_multi_init and add eac...
By default, PHP Curl supports GET and POST requests. It is possible to also send custom requests, such as DELETE, PUT or PATCH (or even non-standard methods) using the CURLOPT_CUSTOMREQUEST parameter. $method = 'DELETE'; // Create a DELETE request $ch = curl_init($url); curl_setopt($ch, CURLOPT...
cURL can keep cookies received in responses for use with subsequent requests. For simple session cookie handling in memory, this is achieved with a single line of code: curl_setopt($ch, CURLOPT_COOKIEFILE, ""); In cases where you are required to keep cookies after the cURL handle is de...
Let's say we have a form like the one below. We want to send the data to our webserver via AJAX and from there to a script running on an external server. So we have normal inputs, a multi-select field and a file dropzone where we can upload multiple files. Assuming the AJAX POST request was succ...
Sending The Request Header $uri = 'http://localhost/http.php'; $ch = curl_init($uri); curl_setopt_array($ch, array( CURLOPT_HTTPHEADER => array('X-User: admin', 'X-Authorization: 123456'), CURLOPT_RETURNTRANSFER =>true, CURLOPT_VERBOSE => 1 )); $out = curl_exec($ch...

Page 1 of 1