I was sending a request to one of the sms gateway providers with HTTP API.
But I am getting 403 Forbidden error. Forbidden You don't have permission to access API/WebSMS/Http/v1.0a/index.php on this server.
My code:-
$url="http://www.somesite.in/API/WebSMS/Http/v1.0a/index.php?username=".$GLOBALS['smsGatewayUsername']."&password=".$GLOBALS['smsGatewayPassword']."&sender=".$GLOBALS['smsGatewaySenderId']."&to=".$mobileNumber."&message=".$message."&reqid=1&format=text&route_id=".$GLOBALS['smsGatewayRouteId']."&sendondate=".$GLOBALS['dateCustom']."&msgtype=unicode";
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
curl_exec ($curl);
curl_close ($curl);
But the $url
works when cop pasted in the browser.
I have enabled the extension=php_curl.dll
inside xampp php.ini
I did this and got the code to work. Instead of passing the parameter as an URL, passed it as postfield option in CURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.somesite.in/API/index.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$GLOBALS['smsGatewayUsername']."&password=".$GLOBALS['smsGatewayPassword']."&sender=".$GLOBALS['smsGatewaySenderId']."&to=".$mobileNumber."&message=".$message."&reqid=1&format=text&route_id=".$GLOBALS['smsGatewayRouteId']."&sendondate=".$GLOBALS['dateCustom']."&msgtype=unicode");
curl_exec($ch);
curl_close($ch);