From 31e711995f66784a9b2ea7c8b8b8d4e9ca581a2c Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sat, 2 Aug 2014 20:39:40 +0200 Subject: [PATCH] Added two examples that uses the class --- README.md | 4 +++ examples/sms_as_args.php | 55 ++++++++++++++++++++++++++++++++++++++++ examples/webpage.php | 49 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 examples/sms_as_args.php create mode 100644 examples/webpage.php diff --git a/README.md b/README.md index 26fcde2..48989a7 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ Parameters for the sendSMS function in order: ## Requirements ## The class requires PHP5 and the PHP5 cURL module (php5-curl on Debian systems). +## Examples ## +In the examples directory are two easy to follow example on how this class can +be used. Both examples should work out of the box as is. + ## Copyright ## This class is written by Jack-Benny Persson and released under GNU GPL version 2. diff --git a/examples/sms_as_args.php b/examples/sms_as_args.php new file mode 100644 index 0000000..e27bbc8 --- /dev/null +++ b/examples/sms_as_args.php @@ -0,0 +1,55 @@ + <'quoted text message'>\n"; + exit(1); +} + +// put arguments into "real" 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); +} + +// if we got to down here, something was wrong, exit with status code 1 +exit(1); + +?> diff --git a/examples/webpage.php b/examples/webpage.php new file mode 100644 index 0000000..5ba1885 --- /dev/null +++ b/examples/webpage.php @@ -0,0 +1,49 @@ + + +Example SMS webpage + + + + +

Send SMS-message

+ +
+Phone number:
+Message:
+
+Sender:
+
+
+_START_HTML_; + +// check if the form has been submitted in which case we send the SMS +if((isset($_POST['phone'])) || (isset($_POST['message'])) || + (isset($_POST['sender']))) +{ + // make variables of the _POST array + $phone = $_POST['phone']; + $message = $_POST['message']; + $sender = $_POST['sender']; + + // instantiate class with $sender and hardcoded user and password + $MySMS = new Cellsynt("myuser", "sEcReT", "alpha", "$sender"); + // call the sendSMS function and print the status-message on the webpage + print "

" . $MySMS->sendSMS($phone, $message) . "

\n"; +} + +?> + + +