| Author |
Message |
Ian Hurrell
New member Username: Ian
Post Number: 1 Registered: 04-2004
| | Posted on Friday, April 23, 2004 - 12:28 am: | |
Hi I know this is basicaly a PHP/script question, but I want a received sms to call a php script, pass the information in the message to the script then send the result back to the sender. The first part is easy but I am not too sure how to get the result to be sent back as an sms. |
Bryce Norwood - NowSMS Support
Board Administrator Username: Bryce
Post Number: 2389 Registered: 10-2002
| | Posted on Saturday, April 24, 2004 - 01:33 am: | |
Hi Ian, I'm not an expert at PHP, but I have been experimenting quite a bit lately ... I guess I know enough to be dangerous. Here's a simple example that is similar to the "echo" command line example in our docs. Let's say you have a 2-way command configured to call http://server/2way.php?sender=@@SENDER@@&text=@@FULLSMS@@ Here's an example of what 2way.php could look like: <? header ("Content-Type: text/plain"); if (isset($_REQUEST['sender'])) { if (isset($_REQUEST['text'])) { echo "I recieved your message : " . $_REQUEST['text']; } else { echo "ERROR : 'text' parameter missing\r\n"; } } else { echo "ERROR : 'sender' parameter missing!\r\n"; } ?> Note that at the start of the script, we set the response content-type to "text/plain". This allows us to configure a command where "Command returns response text" is set. The text that we return in our script response will be sent back as the reply to the message. Here's another example where we use the redirect technique described in http://www.nowsms.com/support/bulletins/tb-nowsms-003.htm: <? header ("Content-Type: text/plain"); if (isset($_REQUEST['sender'])) { if (isset($_REQUEST['text'])) { header ("Location: http://ipaddress:port/?phonenumber=" . $_REQUEST['sender'] . "&text=" . urlencode("I received your message : " . $_REQUEST['text'])); } else { echo "ERROR : 'text' parameter missing\r\n"; } } else { echo "ERROR : 'sender' parameter missing!\r\n"; } ?> In this example, "Command returns response text" should not be checked. The script returns a redirect response which points to a command that tells NowSMS to send a message. Using the redirect technique, we are not limited to only sending text messages, but can send any type of message that can be sent by NowSMS through a URL request. Hopefully that will help ... -bn |
Ian Hurrell
New member Username: Ian
Post Number: 2 Registered: 04-2004
| | Posted on Sunday, April 25, 2004 - 11:02 pm: | |
Thanks Bryce, that's a big help! Ian |
|