This is a sample code assuming we have a sms gateway with name smsgateway.co.cc. We have take a sample
$curlPost = 'Mobile_No=9000099119&Type=SMS&Message="This is a test message"';
//we have to pass the mobile number and message as argument to the url.
$LOGINURL = "http://smsgateway.co.cc/UserMiscellaneousMT.asp";
//This url will be provided by our gateway
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
//setting the browser agent as Firefox
$ch = curl_init();
// initiate a curl function c
url_setopt($ch, CURLOPT_URL,$LOGINURL);
//set the url to be used
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//set the browser
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
//set the maxmium time to execute
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// accept the responce after the execution
curl_setopt($ch, CURLOPT_POST, 1);
// set the post method for passing variables to the server
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
//assigning the post values
$result = curl_exec ($ch);
//executing with the above set options and catching the values in a variable
curl_close ($ch);
// closing the connection
echo $result;
// printing the result.
CURL_INIT():-
The curl_init() function returns a Curl instance for us to use in later functions, and you should always store it for later. It has just one optional parameter: if you pass a string into curl_init(), it will automatically use that string as the URL to work with. In the script above, we use curl_setopt() to do that for clarity, but it is all the same.
Curl_setopt():-
Curl_setopt() takes three parameters, which are the Curl instance to use, a constant value for the setting you want to change, and the value you want to use for that setting. There are a huge number of constants you can use for settings, and many of these are listed shortly. In the example we use CURLOPT_URL:- which is used to set the URL for Curl. CURLOPT_USERAGENT:- which is used to set browseragent for Curl. CURLOPT_CONNECTTIMEOUT:- which is used to set the MAX ececution tiem for Curl. CURLOPT_RETURNTRANSFER:- which is used to set the Returntransfer enable for Curl. CURLOPT_POST:- which is used to set the method of posting the variables for Curl. CURLOPT_POSTFIELDS:- which is used to set the variables for Curl.
curl_exec():-
Calling curl_exec() means, We finished setting our options and ready do it, and you need to pass precisely one parameter: the Curl resource to use. The return value of curl_exec() is true/false by default.
curl_close():-
The final function, curl_close(), takes a Curl resource as its only parameter, closes the Curl session, then frees up the associated memory.