Forum Moderators: coopster

Message Too Old, No Replies

what did i do wrong?

         

professorsunday

3:02 pm on Sep 26, 2009 (gmt 0)

10+ Year Member



i got a api from an sms provider that looks like this
http://www.example.com/api/send_sms.php?user=#*$!xpassword=#*$!x&to=1234&from=#*$!x&content=hello&content_type=text

am writing a php file for my sms site to send message so that the output would give something like the one above. Here is a look at my code:

<?php
session_start();
include($HTTP_SERVER_VARS["DOCUMENT_ROOT"] ."/includes/config.inc.php");
if(isset($_SESSION['user_id'])){
$user_id = $_SESSION['user_id'];
} else {redirect("login.php"); exit();}

$to = $_POST['to'];
$msg = $_POST['msg'];

$num_rows = CountRecords("SELECT * FROM ".TBL_CREDITS." WHERE user_id = $user_id");
if($num_rows >0){
$result = selectFrom("SELECT * FROM ".TBL_CREDITS." WHERE user_id = $user_id");
if($result['credit'] < 1) {
redirect("home.php?p=single&error=true");
}
else {


$username = 'private';
$password = 'private';
$to = $to;
$content = $msg;
$from = $from;

$url = 'http://www.example.com/api/send_sms.php';
/*
* We recommend that you use port 5567 instead of port 80, but your
* firewall will probably block access to this port (see FAQ for more
* details):
* $port = 5567;
*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_PORT, $port);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$post_body = '';

$post_fields = array(
username => $username,
password => $password,
message => $content,
to => $to
from => $from
);

foreach($post_fields as $key=>$value) {
$post_body .= urlencode($key).'='.urlencode($value).'&';
}
$post_body = rtrim($post_body,'&');

curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_body);
$response_string = curl_exec($ch);
$curl_info = curl_getinfo($ch);

if ($response_string == FALSE) {
redirect("home.php?p=single&sent=fail");
} elseif ($curl_info['http_code'] != 200) {
redirect("home.php?p=single&sent=fail");
}
else {
// redirect("home.php?p=single&sent=fail&a=Z");
$result = explode('¦', $response_string);
//print_r($result);
if (count($result) != 3) {
redirect("home.php?p=single&sent=fail&a=A");
} else {
if ($result[0] == '0') {
$amt1 = (int) $result['credit'];
$amt3 = $amt1 - 1;
update("UPDATE ".TBL_CREDITS." SET credit = ".$amt3);
redirect("home.php?p=single&sent=true");
}
else {

if($result[0] == '24')
redirect("home.php?p=single&sent=24&phone=".$to);
else
redirect("home.php?p=single&sent=fail&a=B");

}
}
}

/*

foreach($post_fields as $key=>$value) {
$post_body .= urlencode($key).'='.urlencode($value).'&';
}
$post_body = rtrim($post_body,'&');

curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_body);
$response_string = curl_exec($ch);
$curl_info = curl_getinfo($ch);

if ($response_string == FALSE) {
print "cURL error: ".curl_error($ch)."\n";
} elseif ($curl_info['http_code'] != 200) {
print "Error: non-200 HTTP status code: ".$curl_info['http_code']."\n";
}
else {
print "Response from server:$response_string\n";
$result = split('\¦', $response_string);
if (count($result) != 3) {
print "Error: could not parse valid return data from server.\n".count($result);
} else {
if ($result[0] == '0') {
print "Message sent - batch ID $result[2]\n";
}
else {
print $result[0].'************';
print "<br>Error sending: status code [$result[0]] description [$result[1]]\n";
}
}
}

*/
curl_close($ch);






}

}
else
{
redirect("home.php?p=single&error=true");
}

?>

if i try sending sms through it i get something like, message not sent. what did i do wrong? please help

[edited by: eelixduppy at 10:50 pm (utc) on Sep. 26, 2009]
[edit reason] switched to example.com [/edit]

rocknbil

4:09 pm on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know nothing about sending to SMS, but did you heed this and experiment with it?

/*
* We recommend that you use port 5567 instead of port 80, but your
* firewall will probably block access to this port (see FAQ for more
* details):
* $port = 5567;
*/

uncomment the port assignment so it doesn't default to 80:

/*
* We recommend that you use port 5567 instead of port 80, but your
* firewall will probably block access to this port (see FAQ for more
* details):
*/
$port = 5567;

If it doesn't work, you can always put it back.

professorsunday

10:36 pm on Sep 26, 2009 (gmt 0)

10+ Year Member



ok, i would try this

professorsunday

11:59 pm on Sep 26, 2009 (gmt 0)

10+ Year Member



it didnt work out