동일한 값을 curl을 이용하여 두 곳으로 보낼 수 있는건가요?

동일한 값을 curl을 이용하여 두 곳으로 보낼 수 있는건가요?

QA

동일한 값을 curl을 이용하여 두 곳으로 보낼 수 있는건가요?

본문

<form  action="send.php" .... </form> 를 통해 입력받은 뒤

 

send.php에서 수신된 정보를 

 - 하나는 SMS전송

 - 하나는 Json방식으로 전송

 

두 곳으로 동시에 처리할 수 있을까요?

 

 

    $name            = $_POST['name']; 
    $phone          = $_POST['phone'];
    $contents      = $_POST['name'].'님 감사드립니다.' ;

 


// sms 발송 업체로 전달  ---------------------------------------
    $urlData    = "id=iddd&pwd=pass&sendType=3&phone=$phone&contents=$contents" ;
    $url        = "http://sms.gogo.com//smSend.php"; // Where you want to post data
 
    $ch         = curl_init();                    // Initiate cURL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);  // Tell cURL you want to post something
    curl_setopt($ch, CURLOPT_POSTFIELDS, $urlData); // Define what you want to post
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the output in string format
    curl_exec ($ch); // Execute
    curl_close ($ch); // Close cURL handle
// ---------------------------------------

 


// json 방식으로 수집된 정보 전달 ---------------------------------------
 
   $jsonInfo    = array(
                'name'  =>$name,
                'contents'  =>$contents,
                'phone' =>$phone
                );
    $jsonData   = json_encode($jsonInfo, JSON_UNESCAPED_UNICODE); // 한글 unicode
    $url        = "http://alpha9.com/test/json.php"; // Where you want to URL
 
    $ch         = curl_init();                    // Initiate cURL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);  // Tell cURL you want to post something
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); // Define what you want to post
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the output in string format
    curl_exec ($ch); // Execute
    curl_close ($ch); // Close cURL handle
// ---------------------------------------

이 질문에 댓글 쓰기 :

답변 1

curl을 처음 실행했을땐 일반 형식으로 보내시고

두번째 실행했을 경우 json 형태로 보내시면 됩니다.

쉽게 말해 한번의 실행으로 두곳으로 보낸다고 생각하지마시고

두번을 실행해서 각각으로 보내세요

답변을 작성하시기 전에 로그인 해주세요.
전체 168
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT