Jump to content

[SOLVED] understanding some code


adam291086

Recommended Posts

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

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.
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.