Re-wrote sms_as_args.php to be easier to follow
This commit is contained in:
parent
31e711995f
commit
5c2af79d2a
@ -10,46 +10,69 @@
|
||||
// the class is required...
|
||||
require ("../cellsyntClass.php");
|
||||
|
||||
// check if user entered two arguments
|
||||
if (!isset($argv[1]) || !isset($argv[2]))
|
||||
{
|
||||
print "Usage: $argv[0] <phone nr> <'quoted text message'>\n";
|
||||
exit(1);
|
||||
}
|
||||
// username and password information for the Cellsynt account and
|
||||
// the sender/originator
|
||||
$username = "myuser";
|
||||
$password = "sEcReT";
|
||||
$sender = "From CLI";
|
||||
|
||||
// put arguments into "real" variables for readability
|
||||
// run a sanity check
|
||||
sanitycheck();
|
||||
|
||||
// if we got past the sanity checks above, instantiate the class
|
||||
$cliSMS = new Cellsynt($username, $password, "alpha", $sender);
|
||||
|
||||
// put the arguments into variables for readability
|
||||
$phone = $argv[1];
|
||||
$message = $argv[2];
|
||||
|
||||
// check if the phone number looks valid
|
||||
if (!preg_match("/\d{7,16}/", $phone))
|
||||
{
|
||||
print "That dosen't look like a valid phone number\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// instatiate the class
|
||||
$cliSMS = new Cellsynt("myuser", "sEcReT", "alpha", "From CLI");
|
||||
// call the sendSMS function with the phone number and message
|
||||
$status = $cliSMS->sendSMS($phone, $message);
|
||||
|
||||
// check for an OK message at the start of the line, in that case everything
|
||||
// was fine
|
||||
if (preg_match("/^OK/", $status))
|
||||
{
|
||||
print "Message was sent successfully. Status message reads:\n";
|
||||
print $status . "\n";
|
||||
exit(0);
|
||||
}
|
||||
// if there were no OK message, something didn't work
|
||||
else
|
||||
{
|
||||
print "Something didn't work out as expected. Status message reads:\n";
|
||||
print $status . "\n";
|
||||
exit(1);
|
||||
}
|
||||
// check the status of the message and print the result
|
||||
checkstatus();
|
||||
|
||||
// if we got to down here, something was wrong, exit with status code 1
|
||||
exit(1);
|
||||
|
||||
|
||||
function checkstatus()
|
||||
{
|
||||
global $status;
|
||||
// check for an OK message at the start of the line, in that case everything
|
||||
// was fine
|
||||
if (preg_match("/^OK/", $status))
|
||||
{
|
||||
print "Message was sent successfully. Status message reads:\n";
|
||||
print $status . "\n";
|
||||
exit(0);
|
||||
}
|
||||
// if there were no OK message, something didn't work
|
||||
else
|
||||
{
|
||||
print "Something didn't work out as expected. Status message reads:\n";
|
||||
print $status . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sanitycheck()
|
||||
{
|
||||
global $argv;
|
||||
// check if user entered two arguments
|
||||
if (!isset($argv[1]) || !isset($argv[2]))
|
||||
{
|
||||
print "Usage: $argv[0] <phone nr> <'quoted text message'>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// check if the phone number looks valid
|
||||
if (!preg_match("/\d{7,16}/", $argv[1]))
|
||||
{
|
||||
print "That dosen't look like a valid phone number\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user