PHP execute a external url without redirect (background)
20,273
Perhaps try executing it like so:
<?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);
Comments
-
Nikz almost 2 years
I have a API url for sending SMS and I have to execute this url once i create a new user. Using PHP how can i call the url in background? I have tried
file_get_contents()
My url is like thisWhile using
file_get_contents()
im getting a 'Bad request' due to the change in url where all the '&' got replaced using '&
'. this replaces the username and password which passed to the url.And also tried some other functions like
fopen()
curl()
. unfortunately for all this function im facing the same issue.So which is the proper method for calling this kinda URL.? thanks in advance.
-
chris85 almost 9 yearsIs that URL a variable you are passing to the file_get_contents? Maybe run php.net/manual/en/function.html-entity-decode.php on it before
-
David almost 9 yearsYou should be able to invoke a URL with any of those methods. How are you constructing the request? Presumably you're doing something to HTML-encode the URL, which you shouldn't be doing.
-
Nikz almost 9 yearsalso tried decoding the url 'htmlspecialchars_decode();' etc. but '&' always changed to '&'
-
chris85 almost 9 yearspossible duplicate of php file_get_contents and &
-