Curl functions in PHP

In PHP, cURL (Client URL) is a library and set of functions that allow you to make HTTP requests to remote servers and retrieve data. cURL provides a way to interact with web services, APIs, and other web resources programmatically.

These are four steps involved in working with cURL.
  1. Initialization and create handler
  2. Setting the options
  3. Execution with curl_exec()
  4. Close the cURL handle
DEMO scripts to post data using cURL
This is not only to collect data but we can also submit form data by POST or GET method to a remote URL or server. Curl function supports many other protocols.

Curl support.

We have to first ensure that curl support is available in our server, for this PHP installation is to be checked. The best way is to check is our phpinfo function. Here is a screenshot of phpinfo.
php info curl extension support
If curl support is not available then process is same as adding any other features to PHP. Here is one example. Same can be followed to add curl extensions in PHP. Once the curl support is available then we will start with a simple code by getting url. The first line will initialize a curl instance and then we will use
$my_curl = curl_init();//  cURL resource

// WE will add options to our curl 
curl_setopt($my_curl, CURLOPT_URL, "");
curl_setopt($my_curl, CURLOPT_HEADER, 0);

curl_exec($my_curl); //execute curl function now and display
curl_close($my_curl); // close the curl connection
Reading external url by curl
PHP Scripts
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer