简体   繁体   English

PHP 在没有重定向的情况下执行外部 url(后台)

[英]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.我有一个用于发送短信的 API url,一旦我创建了一个新用户,我就必须执行这个 url。 Using PHP how can i call the url in background?使用 PHP 如何在后台调用 url? I have tried file_get_contents() My url is like this我试过file_get_contents()我的网址是这样的

http://bulksms.mysmsmantra.com/WebSMS/SMSAPI.php?username=hidden&password=hidden&sendername=iZycon&mobileno=8443223 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 ' &在使用file_get_contents()由于 url 的更改,所有 ' & ' 都使用 ' &替换,因此我收到了“错误请求” & '. '。 this replaces the username and password which passed to the url.这将替换传递给 url 的用户名和密码。

And also tried some other functions like fopen() curl() .还尝试了一些其他函数,如fopen() curl() unfortunately for all this function im facing the same issue.不幸的是,对于所有这些功能,我都面临着同样的问题。

So which is the proper method for calling this kinda URL.?那么调用这种 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)错误出现此代码未运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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