【问题标题】:go to url from php and execute the remaining code从php转到url并执行剩余的代码
【发布时间】:2015-02-08 17:36:40
【问题描述】:

这个 php 代码是使用 ajax 执行的。执行标头语句后,Ajax 请求不会返回。

if(is_numeric($phone) && strlen($phone)==10){
        $text = "Hi $name, your account created at hhhhh. Check your email to get updates. Thank you";
        $sms = "http://domain.com/msg.php?user=******&pass=*****&sender=***&phone=$phone&text=$text&priority=****&stype=***";
header("Location: $sms");
    }

    $url = "done";
    echo $url;

我需要的是,只需在 php 中转到 $sms url 并在通过 ajax 调用此代码时执行剩余部分。除了header还有其他方法可以转到链接并在php中执行其余代码。

【问题讨论】:

  • curl做一些研究
  • 为什么要通过 GET 请求发送密码?
  • 短信网关api是这样的。

标签: php jquery ajax


【解决方案1】:

替换

 header("Location: $sms");

 @file_get_contents($sms);

【讨论】:

  • 试过了,代码执行完毕,但收不到短信。
【解决方案2】:

您不能告诉浏览器它应该显示来自不同 URL 的内容同时显示来自当前 URL 的内容。

听起来您应该从服务器向domain.com URL 发出HTTP 请求,在这种情况下,您应该查看cURL 而不是header()

【讨论】:

  • 试过这段代码$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $sms, CURLOPT_USERAGENT => 'SMS' )); $resp = curl_exec($curl); curl_close($curl);代码执行没有错误,但没有收到短信。
猜你喜欢
  • 2012-07-14
  • 2011-10-08
  • 2020-09-05
  • 2017-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多