adam291086 Posted October 15, 2008 Share Posted October 15, 2008 I am looking into creating a API using AQL SMS gateway Here is there example code and there url http://www.aql.com/documents/services/backup_gateway_specification.pdf // your aqsms username and password $username = "yourusername"; $password = "yourpassword"; $path = "/sms/postmsg.php"; $connected = FALSE; $message = "This is a test message"; $number = "44712345678"; // encodes your message for sending on the web $message = urlencode($message); // the request string $smsurl = "$path?username=$username&password=$password&to_num=$number&message=$message"; // connects to server to send message $array_servers = array("gw1.aql.com","gw11.aql.com", "gw2.aql.com","gw22.aql.com"); foreach($array_servers as $server) { //this line sets the server we wish to connect to $connecturl = "http://$server".$smsurl; if($content_array = file($connecturl)) { $connected = TRUE; $content = implode("", $content_array); // check for response if (eregi("AQSMS-AUTHERROR",$content)) echo "There was an authentication error"; elseif (eregi("AQSMS-NOMSG",$content)) echo "There was no message or mobile number"; elseif (eregi("AQSMS-OK",$content)) echo "The Message was queued successfully"; elseif (eregi("AQSMS-NOCREDIT",$content)) echo "Your account has no credit"; break; //this breaks the foreach loop } } if($connected == FALSE) { //none of aql servers were available. //Deal with this situation appropriately echo "There was an error connecting to all aql servers"; } // your aqsms username and password $username = "yourusername"; $password = "yourpassword"; $path = "/sms/postmsg.php"; $connected = FALSE; $message = "This is a test message"; $number = "44712345678"; // encodes your message for sending on the web $message = urlencode($message); // the request string $smsurl = "$path?username=$username&password=$password&to_num=$number&message=$message"; // connects to server to send message $array_servers = array("gw1.aql.com","gw11.aql.com", "gw2.aql.com","gw22.aql.com"); foreach($array_servers as $server) { //this line sets the server we wish to connect to $connecturl = "http://$server".$smsurl; if($content_array = file($connecturl)) { $connected = TRUE; $content = implode("", $content_array); // check for response if (eregi("AQSMS-AUTHERROR",$content)) echo "There was an authentication error"; elseif (eregi("AQSMS-NOMSG",$content)) echo "There was no message or mobile number"; elseif (eregi("AQSMS-OK",$content)) echo "The Message was queued successfully"; elseif (eregi("AQSMS-NOCREDIT",$content)) echo "Your account has no credit"; break; //this breaks the foreach loop } } if($connected == FALSE) { //none of aql servers were available. //Deal with this situation appropriately echo "There was an error connecting to all aql servers"; } i dont understand what this line is doing, can anyone explain if($content_array = file($connecturl)) Link to comment https://forums.phpfreaks.com/topic/128537-solved-understanding-some-code/ Share on other sites More sharing options...
trq Posted October 15, 2008 Share Posted October 15, 2008 It is creating an array ($content_array) from the contents of the file stored in $connecturl. The if condition is simply there to check the file was read correctly before executing anything within the if. eg; if ($content_array = file($connecturl)) { // it is now safe to use the $content_array array. } Link to comment https://forums.phpfreaks.com/topic/128537-solved-understanding-some-code/#findComment-666118 Share on other sites More sharing options...
adam291086 Posted October 15, 2008 Author Share Posted October 15, 2008 ok i see what it is doing. Thanks for the help. Is there a php function to send a http request? Link to comment https://forums.phpfreaks.com/topic/128537-solved-understanding-some-code/#findComment-666120 Share on other sites More sharing options...
trq Posted October 15, 2008 Share Posted October 15, 2008 You may need to look at the curl extension depending on your needs, otherwise a simple call to file_get_contents will usually suffice. Link to comment https://forums.phpfreaks.com/topic/128537-solved-understanding-some-code/#findComment-666121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.