2014-12-21 6 views
-3

내 PHP 페이지를 통해 SMS를 보내고 싶습니다.API 웹 사이트를 방문한 후 내 페이지로 리디렉션하는 방법은 무엇입니까?

처럼 내 API는 " http://sms.xyz.com/uname=abc&pass=xyz&phone=1234567890&msg=hello는" 이

내가 SMS 있도록 내 스크립트 그냥 (이 URL을 방문하려는 (브라우저에서이 URL을 방문하는 전화 번호로 SMS를 전송)

내 SMS 게이트웨이 공급자가 주신 ) 결과를 무시하고 내 페이지로 돌아가서 "보낸 메시지"를 인쇄하십시오.

어떤 방법 으로든 제안하십시오. cURL

+1

웹 사이트 사용자가 자격증 명을 볼 때 cURL 또는'file_get_contents' – sjagr

+0

을 사용하십시오. – kero

+0

대신에 filee_get_contents의 사용법을 알고 curl이 문제를 만들고 있습니다. : – Ashish

답변

0

를 사용하여 메시지를 보내고 응답을하고 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') 
+0

이 send 함수를 어떻게 호출할까요? – Ashish

+0

간단히'send ('9220022002', 'Hello world!');'또는 OOP를 사용한다면 '$ this-> send ('9220022002', 'Hello world!')'; –

관련 문제