简体   繁体   中英

PHP execute a external url without redirect (background)

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 this

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

While 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.

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);

bool(false)错误出现此代码未运行

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM