jossylala Posted September 26, 2009 Share Posted September 26, 2009 got a api from an sms provider that looks like this CODE http://www.frihost.com/api/send_sms.php?user=xxxxpassword=xxxx&to=1234&from=xxxx&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: 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.frihost.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 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 27, 2009 Share Posted September 27, 2009 well setting the $port to something would probably be an idea! also http://www.frihost.com/api/send_sms.php doesn't seam to exist! Quote Link to comment Share on other sites More sharing options...
jossylala Posted September 27, 2009 Author Share Posted September 27, 2009 yes, the frihost.com is just a smple of how the actual url looks like. secondly, i have tried puting port but to no avail. anyother help? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 27, 2009 Share Posted September 27, 2009 yes, the frihost.com is just a smple of how the actual url looks like. secondly, i have tried puting port but to no avail. anyother help? With out details no, I'll need to know where its getting stuck, for example any errors, what do the following functions do CountRecords selectFrom And where are they ? saying doesn't send it the same as saying doesn't work. Quote Link to comment Share on other sites More sharing options...
nicephotog Posted October 12, 2009 Share Posted October 12, 2009 should this $to = $to; be this inside the else section # $to = $to; redundant as some others assigned that way because they will hold their value this if($result[0] == '0') {.... should be if($result[0] == 0) {.... "numeric" if $result[0] is a string php for most is dynaimically typed but that may be only ever a digit and should be checked with if(ereg("^\d+$",$result[0])){#is true......... then do coumpounded if(ereg("^0+$",$result[0])){#is true......... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.