Post data using cUrl in PHP – A simple example
cUrl is very powerful library, which provides various different ways to solve many real life problems. I often use curl in my projects. here is a very basic example of Post data using cUrl in PHP:
NOTE: cURL extension should be enabled in your php.ini to work any curl code. See how to Enable cURL in php
Explanation of above code,
$ch = curl_init(); will initiate the curl session.
$url is the url where you want to post the values. CURLOPT_URL will tell curl that $url to post values is $url.
in curl_setopt() you can set the options for your curl session
CURLOPT_POST if set true, then you can POST the values.
CURLOPT_POSTFIELDS will have all the values to be post on the $url.
CURLOPT_RETURNTRANSFER will tell curl to return values from $url in string format.
curl_exec ($ch); will execute the curl session.
curl_close ($ch); will close curl session.