2013-03-12 3 views
-1

Я использую Curl для отправки sms с помощью шлюза a, получая 200, когда все в порядке, и 400, если он не отправляется сейчас, я должен получить другие вещи от шлюза, такие как номер телефона и другую информацию, поэтому я что-то упускаю ?Curl response in php

// if the Form is submited 
//if (isset($_POST['PhoneNumber'])) { 
if ($_SERVER['REQUEST_METHOD'] == "POST"){ 

// Fetch Phone Number and escape it for security 
$Phone = mysql_real_escape_string($_POST['PhoneNumber']); 

// Fetch Text and escape it for security 
$Text = mysql_real_escape_string($_POST['Text']); 

// Structure the URl 
$url = "http://xxxxxxxxxxx:xxxx?PhoneNumber=".urlencode($Phone)."&Text=".urlencode($Text)."&User=xxx&Password=xxx"; 

// Handeling the Curl 
$handle = curl_init($url); 

curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); 

/* Get the HTML or whatever is linked in $url. */ 
$response = curl_exec($handle); 

/* Check for 404 (file not found). */ 
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); 

if ($httpCode=="200"){ 

    // if everything is okey , the gateway returns 200 which means OK 
    echo "Massage Was Sent , Thank you "; 



} elseif ($httpCode=="400"){ 
    // if there was an error , the form returns a 400 which means that the sms Failed 
    echo "Massage was not sent , Please Try Again"; 

} 

// Cloase the Curl Connection 
curl_close($handle); 

Спасибо С наилучшими пожеланиями,

+0

я не знаком с завитком на всех, но 'curl_getinfo' являются вы уверены, что вам не нужна переменная '$ response'? вы указываете '$ handle'. потому что я думаю, что вы захотите получить информацию об ответе. может быть неправильно. – sircapsalot

+0

Я не понимаю, что мне делать? – test

+0

Спасибо за массаж :) (извините) – kjetilh

ответ

0

$ ответ должен содержать ответ, попробуйте: echo '<pre>'; print_r($response); echo '</pre>'; , чтобы показать его содержание