Php 访问API网站后如何重定向到我自己的页面?

Php 访问API网站后如何重定向到我自己的页面?,php,Php,我想通过我的php页面发送短信 我的短信网关提供商给了我类似的api "" (在浏览器中访问此url会向电话号码发送短信) 我希望我的脚本只访问此url(以便发送sms),然后返回到我自己的页面(无论结果如何),并打印“Message sent” 请建议任何方法。使用cURL发送消息并获得响应,使用header()重定向用户 <?php function send($phone, $msg) { $API_URL = "http://sms.xyz.com/"; $UNAM

我想通过我的php页面发送短信

我的短信网关提供商给了我类似的api "" (在浏览器中访问此url会向电话号码发送短信)

我希望我的脚本只访问此url(以便发送sms),然后返回到我自己的页面(无论结果如何),并打印“Message sent”


请建议任何方法。

使用
cURL
发送消息并获得响应,使用
header()
重定向用户

<?php
function send($phone, $msg)
{
    $API_URL = "http://sms.xyz.com/";
    $UNAME = "abc";
    $PASS = "xyz";

    $query = array(
        'uname'=>$UNAME,
        'pass'=>$PASS,
        'phone'=>$phone,
        'msg'=>$msg
    );
    $url = $API_URL . "?" . http_build_query($query);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url); // set the url to fetch
    curl_setopt($ch, CURLOPT_HEADER, 0); // set headers (0 = no headers in result)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // type of transfer (1 = to string)
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 4000); // time to wait in miliseconds
    $content = curl_exec($ch); // Make the call
    curl_close($ch);

    echo "Response Message == ".$content;   // Response message
}

// Now hit the function
send('9220022002', 'Hello world!');

// and redirect wherever you want
header("location:http://www.google.com");
// or
header("location:/something/anything");
// or
header("location:index.php");

exit();  // always use exit after using header('Location')

使用cURL或
文件获取内容
不要,因为您网站的用户将看到凭据。使用Instead之类的工具我不知道filee\u get\u内容和curl的使用会产生问题(有,您可以理解它的用途。而“cURL正在制造问题”无助于解决问题。您应该在问题中添加详细信息,概述您在使用cURL时遇到的问题以及您尝试解决这些问题的步骤。如何调用此发送函数?只需
send('9220022002',Hello world!')如果您使用的是OOPs,则发送('9220022002','Hello world!')