채택완료
동일한 값을 curl을 이용하여 두 곳으로 보낼 수 있는건가요?
<form action="send.php" .... </form> 를 통해 입력받은 뒤
send.php에서 수신된 정보를
- 하나는 SMS전송
- 하나는 Json방식으로 전송
두 곳으로 동시에 처리할 수 있을까요?
$name = $_POST['name'];
$phone = $_POST['phone'];
$contents = $_POST['name'].'님 감사드립니다.' ;
Copy
// 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
// ---------------------------------------
Copy
// 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개 / 댓글 2개
채택된 답변
+20 포인트
curl을 처음 실행했을땐 일반 형식으로 보내시고
두번째 실행했을 경우 json 형태로 보내시면 됩니다.
쉽게 말해 한번의 실행으로 두곳으로 보낸다고 생각하지마시고
두번을 실행해서 각각으로 보내세요
답변을 작성하려면 로그인이 필요합니다.
Json을 보내면 받는 쪽 처리를 해봐야겠네요