PHP execute external url without redirect (background)

I have an API URL to send SMS and I have to execute this URL after creating a new user. Using PHP, how can I name a URL in the background? I tried file_get_contents() my url is as follows

http://bulksms.mysmsmantra.com/WebSMS/SMSAPI.php?username=hidden&password=hidden&sendername=iZycon&mobileno=8443223

When using file_get_contents()im, receiving an โ€œunsuccessful requestโ€ due to a change in the URL where everything is โ€œ and โ€ replaced with โ€œ , it replaces the username and password that are passed to the URL. &

And also tried some other functions, such as fopen() curl(). unfortunately, for all this function im is facing the same problem.

So what is the correct method to call this url? thanks in advance.

+4
source share
1 answer

Perhaps try executing it like this:

<?php    
$url = 'http://bulksms.mysmsmantra.com/WebSMS/SMSAPI.php';

$fields = array(
    'username'      => "hidden",
    'password'      => "hidden",
    'sendername'    => "iZycon",
    'mobileno'      => 8443223
);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

var_dump($result);
+7
source

All Articles