SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SMS Based Registration System problem response message via SMS

    Hi;

    I am a newbie in developing an SMS Based system particularly in the use of php nusoap libraries. Right now i am having difficulty achieving success in testing my SMS system. What i am trying to do was that i want to register as a user using SMS by texting REG NAME AGE LOCALCHURCH DISTRICT and send to 23730731 my access code. Here's what i did:
    ***Register.php***

    Code PHP:
    <?php
    // This will allow user to register via SMS.
    error_reporting(0);
     
     
    // load the nusoap libraries. These are slower than those built in PHP5 but don't require you to recompile PHP
    include_once('nusoap.php');
     
    // create the client and define the URL endpoint
    $client = new nusoap_client('http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform/');
     
    // set the character encoding, utf-8 is the standard.
    $client->soap_defencoding = 'UTF-8';
    $client->call('sendSMS', array( 'uName' => '48dwi5',
    'uPin' => '159597',
    'MSISDN' => '09152886810',
    'messageString' => 'Registered Successfully',
    'Display' => '1',
    'udh' => '',
    'mwi' => '',
    'coding' => '0' ),
    "http://ESCPlatform/xsd");
    ?>

    Here is also the xml format of texting SMS via 23730731.
    Code XML:
    <?xml version="1.0" encoding="utf-8"?>
    <message>
    <param>
          <name>id</name>
          <value>2373094420110106170141</value>
    </param>
       <param>
          <name>messageType</name>
          <value>SMS</value>
       </param>
       <param>
          <name>target</name>
          <value>23730731</value>
       </param>
       <param>
          <name>source</name>
          <value>09152886810</value>
       </param>
       <param>
          <name>msg</name>
          <value>REG</value>
       </param>
       <param>
              <name>msg</name> 
    	  <value>NAME</value> 
      </param>
     <param>
    	 <name>msg</name>
    	 <value>AGE</value> 
     </param> 
    <param> 
    	 <name>msg</name>
    	 <value>LOCAL CHURCH</value> 
        </param> 
           <param>
    	 <name>msg</name>
    	 <value>DISTRICT</value>
          </param>
          <param>
          <name>udh</name>
          <value></value>
       </param>
       </message>

    After registration,they will receive a confirmation that they successfully registered as user and they will be allowed to inquire via SMS. Here's the my php code:
    ***inquire.php***

    Code PHP:
    <?php
    // This will allow user to inquire about the latest news within the organization.
    // load the nusoap libraries. These are slower than those built in PHP5 but don't require you to recompile PHP
    require_once('nusoap.php');
    $client = new nusoap_client('http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform/sendSMS');
    // set the character encoding, utf-8 is the standard.
    $client->soap_defencoding = 'UTF-8';
    // Call the SOAP method, note the definition of the xmlnamespace as the third parameter in the call and how the posted message is added to the message string
     $client->call('sendSMS', array( 'uName' => '48dwi5', 
    'uPin' => '159597', 
    'MSISDN' => '09152886810', 
    'messageString' => 'Summer Camp 2013', 
    'Display' => '1', 
    'udh' => '', 
    'mwi' => '', 
    'coding' => '0' ), 
    "http://ESCPlatform/xsd");
     
    ?>

    Here's the xml format of sending inquiries via SMS. They will send INQ EVENT LOCATION TIME send to 23730731.
    Code XML:
    <?xml version="1.0" encoding="utf-8"?>
    <message>
       <param>
       <name>id</name>
          <value>2373094420110106170141</value>
     
       </param>
       <param>
          <name>messageType</name>
          <value>SMS</value>
       </param>
       <param>
          <name>target</name>
          <value>23730731</value>
       </param>
       <param>
          <name>source</name>
          <value>09152886810</value>
       </param>
       <param>
          <name>msg</name>
          <value>event</value>
       </param>
    <param>
          <name>msg</name>
          <value>location</value>
       </param>
     
    <param>
          <name>msg</name>
          <value>time</value>
       </param>
     
     
       <param>
          <name>udh</name>
          <value></value>
       </param>
    </message>

    Here's my callback URL to receive the message sent:

    Code PHP:
    <?php
     
    function send($number,$client)
    {
     
    $x=send("09152886810",$client);
    echo $x;
    }
     
    # Load XML string from input
    
    $xml = simplexml_load_file('php://input');
     
    # Parse the XML for parameters
    
    $sms = array();
    $nodes = $xml->xpath('/message/param');
     
    foreach($nodes as $node)
     {
       $param = (array) $node;
     
    $sms[$param['name']] = $param['value'];
     
    }
     
     
     
     
    if($sms['messageType'] == 'SMS-NOTIFICATION') {
    send();
     
    list($action, $messagetype, $source, $type) =explode ("     ",$client); 
     
     
     
     
    }elseif($sms['messageType'] == 'SMS') {
     
     
     
    send();   
    list($action, $name, $age, $localchurch, $district) = explode(" ",$client); 
     
     
    }elseif($sms['messageType'] == 'SMS') {
     
     
    send(); 
    list($action, $event,$location,$time) = explode("     ", $client);
     
     
     
    }
    else {
       echo "Unsupported Message Type";
     
    }
     
     
     
     
    ?>
    Last edited by Mittineague; Apr 17, 2013 at 13:56. Reason: reformatting bbcode tags

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    So... what's the question?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    So... what's the question?
    The problem was when i tried to test my system via SMS,i receive nothing when i tried for example, to register via SMS based on the code that i have, it does not even respond nor insert data into mysql. what i want is to register a user via SMS using the above xml code. And also they will receive a confirmation that they were successfully registered as a user. And eventually, will allow them to inquire via SMS like INQ EVENT via 23730731. The server will then respond the event via mysql.

    Here's my soap server code for inserting registered user info into mysql:

    Code: php

    Code PHP:
    <?php
    //call library
    require_once ('nusoap.php');
     
    //using soap_server to create server object
    $server = new nusoap_server;
    $server ->configureWSDL('http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform/sendSMS','http://ESCPlatform/xsd');
    //register a function that works on server
    $server->register('reg');
     
    // create the function
    function reg()
    {
    $connect = mysql_connect("localhost","root","jya0312@");
     
    if (!$connect)
    {
    die("Couldnt connect" . mysql_error());
    }
     
    mysql_select_db("cyfdb", $connect);
     
    $sql = "INSERT INTO mydb(name, age,localchurch,district) VALUES ('{$_POST[name]}','{$_POST[age]}','{$_POST[localchurch]}','{$_POST[district]}')";
     
    mysql_close($connect);
     
    }
     
    // create HTTP listener
    $server->service($HTTP_RAW_POST_DATA);
     
    exit();
     
    ?>

    This is for texting inquiry via SMS:

    Code PHP:
    <?php
    //call library
    require_once ('nusoap.php');
     
    //using soap_server to create server object
    $server = new nusoap_server;
    $server ->configureWSDL('http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform/sendSMS','http://ESCPlatform/xsd');
    //register a function that works on server
    $server->register('getquery');
     
    // create the function
    function getquery()
    {
    $link=mysql_connect("localhost", "root", "jya0312@") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql = "SELECT event,location,time from activity";
    while($r = mysql_fetch_array($sql)){
    	  $items[] = array('event'=>$r['event'],
                              'location'=>$r['location'],
                              'date'=>$r['date']); 
    	}
    	return $items;
     
     
    $mysql_close($link);
     
     
    	}
     
    // create HTTP listener
    $server->service($HTTP_RAW_POST_DATA);
     
    exit();
    ?>
    Last edited by Mittineague; Apr 20, 2013 at 09:33. Reason: reformatting bbcode tags

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, what's up?Can u help me on this?I need it asap.thanks

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to follow up if you solve the problem?

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    I'm.. not sure how this implementation works.

    Where's the API documentation for the service you are using to send/receive SMS's? How does the system know to call your PHP page?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    API Services that i am using

    Quote Originally Posted by StarLion View Post
    I'm.. not sure how this implementation works.

    Where's the API documentation for the service you are using to send/receive SMS's? How does the system know to call your PHP page?

    Here's the link of my API documentation that i used to develop my system:

    https://www.globelabs.com.ph/api/Pag...me.aspx?WId=11

    I am using our very own Globe Labs API documentation.
    The system will call my php page by having it connected to my web server as a web service.
    Thank you very much.

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jyambao View Post
    Here's the link of my API documentation that i used to develop my system:

    https://www.globelabs.com.ph/api/Pag...me.aspx?WId=11

    I am using our very own Globe Labs API documentation.
    The system will call my php page by having it connected to my web server as a web service.
    Thank you very much.
    I am using a web service link to send and receive message via SMS :
    http://iplaypen.globelabs.com.ph:188...atform/sendSMS

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I cant access your API documentation because i'm not a subscriber of that website.

    I have no idea if your program is correct, because i dont know what the function is meant to return, if it's returning the correct values, etc.

    Does Globe Labs not provide support for their product?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Globe labs API Documentation

    Quote Originally Posted by StarLion View Post
    Yeah, I cant access your API documentation because i'm not a subscriber of that website.

    I have no idea if your program is correct, because i dont know what the function is meant to return, if it's returning the correct values, etc.

    Does Globe Labs not provide support for their product?
    I will send instead, the API Documentation, there are some sample code provided in their site.
    but not exactly what i wanted to do.

    Using the API is fairly straightforward. It was designed to allow easy integration between different platforms and languages using the SOAP protocol. Let's create a simple application which allows a webpage to send an SMS message.
    Code PHP:
    <?php
    // load the nusoap libraries. These are slower than those built in PHP5 but don't require you to recompile PHP
    include_once("nusoap/lib/nusoap.php");
    // create the client and define the URL endpoint
    $client = new soapclient('http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform/');
    // set the character encoding, utf-8 is the standard.
    $client->soap_defencoding = 'UTF-8';
    // check if we generated an error in creating the client / assigning the endpoint
    $err = $client->getError();
     
    if ($err)
    {// Display the error
            $error_message = 'Constructor error: ' . $err;
    }
    // check if a message was sent
    if (!empty($_POST['send']))
    {// Call the SOAP method, note the definition of the xmlnamespace as the third parameter in the call and how the posted message is added to the message string
            $result = $client->call('sendSMS', array( 'uName' => 'username',
    'uPin' => 'password',
    'MSISDN' => '0917xxxxxxx',
    'messageString' => $_POST['msg'],
    'Display' => '0',
    'udh' => '',
    'mwi' => '',
    'coding' => '0' ),
    "http://ESCPlatform/xsd");
     
    // Check for a fault
            if ($client->fault)
            {
                    $error_message = "Fault Generated: \n";
            }
            else
            {// Check for errors
                    $err = $client->getError();
     
                    if ($err)
                    {// Display the error
                            $error_message = "An unknown error was generated: \n";
                    }
                    else
                    {// Display the result
                            if ($result == "201")
                            {
                                    $error_message = "Message was successfully sent!";
                            }
                            else
                            {
                                    $error_message = "Server responded with a $result message";
                            }
                    }
            }
    }// end if

    HTML Code:
    <html>
    <head></head>
    <body>
    <h1>SMS API Demo</h1>
    <p>Type in your message below and I'll be able to get your message via SMS.</p>
    <form method="post">
    <textarea name="msg"></textarea>
    <br>
    <input type="submit" name="send" value="Send">
    </form>
    <div style="color: red"><?php echo $error_message ?></div>
    </body>
    For this example, we’ve used PHP and NuSOAP. Most web hosting services these days provide PHP support at very affordable prices. Some of hosting providers may not provide built-in SOAP support in PHP5 This is where the NuSOAP library comes in handy.
    The first line below shows the script creating a new instance of the soapclient class (as defined in the NuSOAP library). The constructor takes an URL endpoint as an argument and then checks if the URL endpoint is valid. On the second line, we set the text encoding parameter to utf-8.
    Code PHP:
    $client = new soapclient( 'http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform/');
    $client->soap_defencoding = 'UTF-8';

    The code below shows the soapclient object executing a call() method. The call() function does the actual work of creating a SOAP-compatible XML message and also sends the XML to our predefined endpoint.
    The call method takes three arguments: the remote method to be called (sendSMS), the parameters for the remote call (an associative array that matches the parameters of the web-service) and finally the XML namespace to be used in the SOAP call ("http://ESCPlatform/xsd"). Make sure to define your own username, password and MSISDN.
    At the minimum, we need to define a username, password and a target MSISDN as parameters. Now to send a message that our application user had just typed, we merely set the “messageString” parameter to take its input from the HTTP-POST request sent by the user.
    Code PHP:
    $result = $client->call('sendSMS', array(  'uName' => 'username',
    'uPin' => 'password',
    'MSISDN' => '0917xxxxxxx',
    'messageString' => $_POST['msg'],
    'Display' => '0',
    'udh' => '',
    'mwi' => '',
    'coding' => '0' ),
    "http://ESCPlatform/xsd");

    The other bits of code in the example perform error handling in case of failures. $client->fault is used when the SOAP service itself generates a error. The service will send SOAP envelope containing fault related elements and nodes. $client->getError(), on the other hand, is a method made available by NuSOAP for non standard failure modes such as timeouts. Finally, the code also processes the $result variable which contains the response of the web service to the request we made. In the example application, receiving a 201 code means that the message has successfully been sent.
    Last edited by Mittineague; Dec 12, 2013 at 23:19. Reason: reformatting bbcode tags

  11. #11
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    That shows how you send an SMS, which is the simple part. My question was more about the API to receive one. You shouldn't need to call the web service if their system sends the message to your page; it should surely be delivered as POST payload data along with the call...

    Also, your code looks nothing like this documentation.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  12. #12
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    That shows how you send an SMS, which is the simple part. My question was more about the API to receive one. You shouldn't need to call the web service if their system sends the message to your page; it should surely be delivered as POST payload data along with the call...

    Also, your code looks nothing like this documentation.
    I just doing an experiment if my code will work but it doesn't , that is why i am asking for help.It's my 2nd course, i repeat my master's program because of this.

    Here's what i did to receive messages from sender and will store in a database.

    ***ReceiveSMS.php***
    Code PHP:
    <?php
     
    $db=mysql_connect("localhost" ,"root", "jya0312@")or die("Cannot connect to DB!");
    mysql_select_db("cyfdb")or die("Cannot connect to DB!");/* select the database to use */
     
     
    /* change behavior depending on the type of request. If we receive a POST request, then parse the XML document embedded within and save to the database. We can add additional validation logic later */
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      /* the php://input file is a PHP built-in that returns raw HTTP-POST data */
      $in = file_get_contents ("php://input");
     
      /* temporary storage */
      $list = array();
     
      /* available in PHP5 is the DOMDocument class which we can use to parse XML */
      $doc = new DOMDocument();
      $doc->loadXML($in);
     
      /* here we just iterate through the XML and store the data points into the $list array */
      $params = $doc->getElementsByTagName( "param" );
      foreach( $params as $param )
      {
        $names = $param->getElementsByTagName( "name" );
        $name = $names->item(0)->nodeValue;
     
        $values = $param->getElementsByTagName( "value" );
        $value = $values->item(0)->nodeValue;
     
        $list[$name] = "'".mysql_escape_string($value)."'";
      }
     
     
      $sql = "insert into incoming(".join(",", array_keys($list)).") values (" . join("," , $list) . ")";
      mysql_query($sql, $db);
    }
    else {
      /* here we just display the sent messages. The header function just loads directs the browser to reload the page every 5 seconds*/
     
      $sql = "select * from incoming order by id";
      $result = mysql_query($sql, $db);
     
      while ($arr = mysql_fetch_array($result, MYSQL_ASSOC)) {
     
        foreach ($arr as $val) {
          echo "$val";
        }
     
      }
      }
    $mysql_close($db);
     
    ?>

    ***incoming_sms.php***
    Code PHP:
    <?php
     
    function send($number,$client)
    {
     
    $x=send("09152886810",$client);
     
     
     
    # Load XML string from input
    
    $xml = simplexml_load_file('php://input');
     
    # Parse the XML for parameters
    
    $sms = array();
    $nodes = $xml->xpath('/message/param');
     
    foreach($nodes as $node)
     {
       $param = (array) $node;
     
    $sms[$param['name']] = $param['value'];
     
    }
     
     
     
     
    if($sms['messageType'] == 'SMS-NOTIFICATION') {
    send();
     
    list($action, $messagetype, $source, $type) =explode ("     ",$data); 
     
     
     
     
    }elseif($sms['messageType'] == 'SMS') {
     
     
     
    send();   
    list($action, $name, $age, $localchurch, $district) = explode(" ",$data); 
     
     
    }elseif($sms['messageType'] == 'SMS') {
     
     
    send(); 
    list($action, $event,$location,$time) = explode("     ", $data);
     
     
     
    }
    else {
       echo "Unsupported Message Type";
     
    }
     
     
    }
     
    ?>
    I tried this code but doesn't work.
    Last edited by Mittineague; Dec 12, 2013 at 23:22. Reason: reformatting bbcode tags

  13. #13
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what i did to receive a message from client:
    Code PHP:
    function globe_receive_sms(){
     $in = file_get_contents("php://input");
     /* temporary storage */
     $list = array();
     
     
     /* available in PHP5 is the DOMDocument class which we can use to parse XML */
     $doc = new DOMDocument();
     
     $doc->loadXML($in);
     
     /* here we just iterate through the XML and store the data points into the $list 
     
    array */
     $params = $doc->getElementsByTagName("param");
     foreach( $params as $param )
    {
     
     $names = $param->getElementsByTagName("name");
     $name = $names->item(0)->nodeValue;
     
     $values = $param->getElementsByTagName("value");
     $value = $values->item(0)->nodeValue;
     
     $list[$name] = mysql_escape_string($value);
    list($action, $name, $age, $localchurch, $district) = $list;
    list($action, $event,$location,$time) = $list;
     
     }
     
    if list=($action, $name, $age, $localchurch, $district)
    {
       $action== reg 
    {
    $db=mysql_connect("localhost", "root", "******") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql="INSERT INTO mydb (name,age,localchurch,district) 
    VALUES ('$name','$age','$localchurch','$district')";
    $r = mysql_query($sql);
    if(!$r) {
     
        $err=mysql_error();
     
        print $err;
     
        exit();}
    $mysql_close($db);
     
     
     
    }
    }
     
    else if($action== inq)
     
    {
    $link=mysql_connect("localhost", "root", "jya0312@") or die("Cannot connect to 
     
    DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql = "SELECT event,location,time from activity";
    while($r = mysql_fetch_array($sql)){
    	  $items[] = array('event'=>$r['event'],
                              'location'=>$r['location'],
                              'date'=>$r['date']); 
    	}
    	return $items;
     
     
    $mysql_close($link);
     
     
    	}
     
     
     
     
     
     return $list;
     
     }
    Quote Originally Posted by jyambao View Post
    I just doing an experiment if my code will work but it doesn't , that is why i am asking for help.It's my 2nd course, i repeat my master's program because of this.

    Here's what i did to receive messages from sender and will store in a database.

    ***ReceiveSMS.php***
    <?php

    $db=mysql_connect("localhost" ,"root", "jya0312@")or die("Cannot connect to DB!");
    mysql_select_db("cyfdb")or die("Cannot connect to DB!");/* select the database to use */


    /* change behavior depending on the type of request. If we receive a POST request, then parse the XML document embedded within and save to the database. We can add additional validation logic later */
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    /* the php://input file is a PHP built-in that returns raw HTTP-POST data */
    $in = file_get_contents ("php://input");

    /* temporary storage */
    $list = array();

    /* available in PHP5 is the DOMDocument class which we can use to parse XML */
    $doc = new DOMDocument();
    $doc->loadXML($in);

    /* here we just iterate through the XML and store the data points into the $list array */
    $params = $doc->getElementsByTagName( "param" );
    foreach( $params as $param )
    {
    $names = $param->getElementsByTagName( "name" );
    $name = $names->item(0)->nodeValue;

    $values = $param->getElementsByTagName( "value" );
    $value = $values->item(0)->nodeValue;

    $list[$name] = "'".mysql_escape_string($value)."'";
    }


    $sql = "insert into incoming(".join(",", array_keys($list)).") values (" . join("," , $list) . ")";
    mysql_query($sql, $db);
    }
    else {
    /* here we just display the sent messages. The header function just loads directs the browser to reload the page every 5 seconds*/

    $sql = "select * from incoming order by id";
    $result = mysql_query($sql, $db);

    while ($arr = mysql_fetch_array($result, MYSQL_ASSOC)) {

    foreach ($arr as $val) {
    echo "$val";
    }

    }
    }
    $mysql_close($db);

    ?>

    ***incoming_sms.php***
    <?php

    function send($number,$client)
    {

    $x=send("09152886810",$client);



    # Load XML string from input

    $xml = simplexml_load_file('php://input');

    # Parse the XML for parameters

    $sms = array();
    $nodes = $xml->xpath('/message/param');

    foreach($nodes as $node)
    {
    $param = (array) $node;

    $sms[$param['name']] = $param['value'];

    }




    if($sms['messageType'] == 'SMS-NOTIFICATION') {
    send();

    list($action, $messagetype, $source, $type) =explode (" ",$data);




    }elseif($sms['messageType'] == 'SMS') {



    send();
    list($action, $name, $age, $localchurch, $district) = explode(" ",$data);


    }elseif($sms['messageType'] == 'SMS') {


    send();
    list($action, $event,$location,$time) = explode(" ", $data);



    }
    else {
    echo "Unsupported Message Type";

    }


    }

    ?>
    I tried this code but doesn't work.
    Last edited by Mittineague; Dec 12, 2013 at 23:23. Reason: reformatting bbcode tags

  14. #14
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jyambao View Post
    I just doing an experiment if my code will work but it doesn't , that is why i am asking for help.It's my 2nd course, i repeat my master's program because of this.

    Here's what i did to receive messages from sender and will store in a database.

    ***ReceiveSMS.php***
    <?php

    $db=mysql_connect("localhost" ,"root", "jya0312@")or die("Cannot connect to DB!");
    mysql_select_db("cyfdb")or die("Cannot connect to DB!");/* select the database to use */


    /* change behavior depending on the type of request. If we receive a POST request, then parse the XML document embedded within and save to the database. We can add additional validation logic later */
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    /* the php://input file is a PHP built-in that returns raw HTTP-POST data */
    $in = file_get_contents ("php://input");

    /* temporary storage */
    $list = array();

    /* available in PHP5 is the DOMDocument class which we can use to parse XML */
    $doc = new DOMDocument();
    $doc->loadXML($in);

    /* here we just iterate through the XML and store the data points into the $list array */
    $params = $doc->getElementsByTagName( "param" );
    foreach( $params as $param )
    {
    $names = $param->getElementsByTagName( "name" );
    $name = $names->item(0)->nodeValue;

    $values = $param->getElementsByTagName( "value" );
    $value = $values->item(0)->nodeValue;

    $list[$name] = "'".mysql_escape_string($value)."'";
    }


    $sql = "insert into incoming(".join(",", array_keys($list)).") values (" . join("," , $list) . ")";
    mysql_query($sql, $db);
    }
    else {
    /* here we just display the sent messages. The header function just loads directs the browser to reload the page every 5 seconds*/

    $sql = "select * from incoming order by id";
    $result = mysql_query($sql, $db);

    while ($arr = mysql_fetch_array($result, MYSQL_ASSOC)) {

    foreach ($arr as $val) {
    echo "$val";
    }

    }
    }
    $mysql_close($db);

    ?>

    ***incoming_sms.php***
    <?php

    function send($number,$client)
    {

    $x=send("09152886810",$client);



    # Load XML string from input

    $xml = simplexml_load_file('php://input');

    # Parse the XML for parameters

    $sms = array();
    $nodes = $xml->xpath('/message/param');

    foreach($nodes as $node)
    {
    $param = (array) $node;

    $sms[$param['name']] = $param['value'];

    }




    if($sms['messageType'] == 'SMS-NOTIFICATION') {
    send();

    list($action, $messagetype, $source, $type) =explode (" ",$data);




    }elseif($sms['messageType'] == 'SMS') {



    send();
    list($action, $name, $age, $localchurch, $district) = explode(" ",$data);


    }elseif($sms['messageType'] == 'SMS') {


    send();
    list($action, $event,$location,$time) = explode(" ", $data);



    }
    else {
    echo "Unsupported Message Type";

    }


    }

    ?>
    I tried this code but doesn't work.
    Code PHP:
    function globe_receive_sms(){
     $in = file_get_contents("php://input");
     /* temporary storage */
     $list = array();
     
     
     /* available in PHP5 is the DOMDocument class which we can use to parse XML */
     $doc = new DOMDocument();
     
     $doc->loadXML($in);
     
     /* here we just iterate through the XML and store the data points into the $list 
     
    array */
     $params = $doc->getElementsByTagName("param");
     foreach( $params as $param )
    {
     
     $names = $param->getElementsByTagName("name");
     $name = $names->item(0)->nodeValue;
     
     $values = $param->getElementsByTagName("value");
     $value = $values->item(0)->nodeValue;
     
     $list[$name] = mysql_escape_string($value);
    list($action, $name, $age, $localchurch, $district) = $list;
    list($action, $event,$location,$time) = $list;
     
     }
     
    if list=($action, $name, $age, $localchurch, $district)
    {
       $action== reg 
    {
    $db=mysql_connect("localhost", "root", "******") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql="INSERT INTO mydb (name,age,localchurch,district) 
    VALUES ('$name','$age','$localchurch','$district')";
    $r = mysql_query($sql);
    if(!$r) {
     
        $err=mysql_error();
     
        print $err;
     
        exit();}
    $mysql_close($db);
     
     
     
    }
    }
     
    else if($action== inq)
     
    {
    $link=mysql_connect("localhost", "root", "jya0312@") or die("Cannot connect to 
     
    DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql = "SELECT event,location,time from activity";
    while($r = mysql_fetch_array($sql)){
    	  $items[] = array('event'=>$r['event'],
                              'location'=>$r['location'],
                              'date'=>$r['date']); 
    	}
    	return $items;
     
     
    $mysql_close($link);
     
     
    	}
     
     
     
     
     
     return $list;
     
     }
    Last edited by Mittineague; Dec 12, 2013 at 23:25. Reason: reformatting bbcode tags

  15. #15
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jyambao View Post
    function globe_receive_sms(){
    $in = file_get_contents("php://input");
    /* temporary storage */
    $list = array();


    /* available in PHP5 is the DOMDocument class which we can use to parse XML */
    $doc = new DOMDocument();

    $doc->loadXML($in);

    /* here we just iterate through the XML and store the data points into the $list

    array */
    $params = $doc->getElementsByTagName("param");
    foreach( $params as $param )
    {

    $names = $param->getElementsByTagName("name");
    $name = $names->item(0)->nodeValue;

    $values = $param->getElementsByTagName("value");
    $value = $values->item(0)->nodeValue;

    $list[$name] = mysql_escape_string($value);
    list($action, $name, $age, $localchurch, $district) = $list;
    list($action, $event,$location,$time) = $list;

    }

    if list=($action, $name, $age, $localchurch, $district)
    {
    $action== reg
    {
    $db=mysql_connect("localhost", "root", "******") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql="INSERT INTO mydb (name,age,localchurch,district)
    VALUES ('$name','$age','$localchurch','$district')";
    $r = mysql_query($sql);
    if(!$r) {

    $err=mysql_error();

    print $err;

    exit();}
    $mysql_close($db);



    }
    }

    else if($action== inq)

    {
    $link=mysql_connect("localhost", "root", "jya0312@") or die("Cannot connect to

    DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql = "SELECT event,location,time from activity";
    while($r = mysql_fetch_array($sql)){
    $items[] = array('event'=>$r['event'],
    'location'=>$r['location'],
    'date'=>$r['date']);
    }
    return $items;


    $mysql_close($link);


    }





    return $list;

    }
    I tried this using codepad and receive no error message: http://codepad.org/DGgJlcX1

  16. #16
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Post #12:
    Quote Originally Posted by jyambao View Post
    I tried this code but doesn't work.
    Well, for starters, this wont work:
    PHP Code:
    function send($number,$client
    followed by
    PHP Code:
    send(); 
    You're not passing parameters to a function expecting them.

    Have you got Error Reporting turned on in these scripts? If not, you really should for debugging purposes.

    Post 13:
    PHP Code:
    if list=($action$name$age$localchurch$district
    Now i'm almost certain you DONT have error reporting enabled because that would have flagged up as well. (No $ before list)

    In fact, there are numerous instances of errors in the scripts above that should have been caught by the PHP Error Reporting. Please enable that;
    At the top of each page;
    PHP Code:
    <?php
    ini_set
    ('display_errors',1); 
    error_reporting(E_ALL);
    and start trying to eliminate the errors that (should) appear. You may need a way to fake (or deliberately trigger; does the service offer a 'sandbox' or 'test your script' bit?) the POST data being sent in to your script.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  17. #17
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Post #12:

    Well, for starters, this wont work:
    PHP Code:
    function send($number,$client
    followed by
    PHP Code:
    send(); 
    You're not passing parameters to a function expecting them.

    Have you got Error Reporting turned on in these scripts? If not, you really should for debugging purposes.

    Post 13:
    PHP Code:
    if list=($action$name$age$localchurch$district
    Now i'm almost certain you DONT have error reporting enabled because that would have flagged up as well. (No $ before list)

    In fact, there are numerous instances of errors in the scripts above that should have been caught by the PHP Error Reporting. Please enable that;
    At the top of each page;
    PHP Code:
    <?php
    ini_set
    ('display_errors',1); 
    error_reporting(E_ALL);
    and start trying to eliminate the errors that (should) appear. You may need a way to fake (or deliberately trigger; does the service offer a 'sandbox' or 'test your script' bit?) the POST data being sent in to your script.
    This is my new php code for receiving messages:
    Code PHP:
    function globe_receive_sms(){
     $in = file_get_contents("php://input");
     /* temporary storage */
     $list = array();
     
     
     /* available in PHP5 is the DOMDocument class which we can use to parse XML */
     $doc = new DOMDocument();
     
     $doc->loadXML($in);
     
     /* here we just iterate through the XML and store the data points into the $list array */
     $params = $doc->getElementsByTagName("param");
     foreach( $params as $param )
    {
     
     $names = $param->getElementsByTagName("name");
     $name = $names->item(0)->nodeValue;
     
     $values = $param->getElementsByTagName("value");
     $value = $values->item(0)->nodeValue;
     
     $list[$name] = mysql_escape_string($value);
    list($action, $name, $age, $localchurch, $district) = $list;
    list($action, $event,$location,$time) = $list;
     
     }
     
    if $list=($action, $name, $age, $localchurch, $district)
    {
       $action== reg 
    {
    $db=mysql_connect("localhost", "root", "******") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql="INSERT INTO mydb (name,age,localchurch,district) 
    VALUES ('$name','$age','$localchurch','$district')";
    $r = mysql_query($sql);
    if(!$r) {
     
        $err=mysql_error();
     
        print $err;
     
        exit();}
    $mysql_close($db);
     
     
     
    }
    }
     
    else if($action== inq)
     
    {
    $link=mysql_connect("localhost", "root", "jya0312@") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql = "SELECT event,location,time from activity";
    while($r = mysql_fetch_array($sql)){
    	  $items[] = array('event'=>$r['event'],
                              'location'=>$r['location'],
                              'date'=>$r['date']); 
    	}
    	return $items;
     
     
    $mysql_close($link);
     
     
    	}
     
     
     
     
     
     return $list;
     
     }

    My problem is the logic behind to select either registration or inquiry via SMS.Which one will be the first to use?My server right now has been deactivated since i am not yet defending my master thesis until next year so what i am doing is to ask some help before i test my system.
    Last edited by Mittineague; Dec 12, 2013 at 23:08. Reason: reformatting bbcode tags

  18. #18
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Receiving SMS code

    Quote Originally Posted by jyambao View Post
    This is my new php code for receiving messages:
    function globe_receive_sms(){
    $in = file_get_contents("php://input");
    /* temporary storage */
    $list = array();


    /* available in PHP5 is the DOMDocument class which we can use to parse XML */
    $doc = new DOMDocument();

    $doc->loadXML($in);

    /* here we just iterate through the XML and store the data points into the $list array */
    $params = $doc->getElementsByTagName("param");
    foreach( $params as $param )
    {

    $names = $param->getElementsByTagName("name");
    $name = $names->item(0)->nodeValue;

    $values = $param->getElementsByTagName("value");
    $value = $values->item(0)->nodeValue;

    $list[$name] = mysql_escape_string($value);
    list($action, $name, $age, $localchurch, $district) = $list;
    list($action, $event,$location,$time) = $list;

    }

    if $list=($action, $name, $age, $localchurch, $district)
    {
    $action== reg
    {
    $db=mysql_connect("localhost", "root", "******") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql="INSERT INTO mydb (name,age,localchurch,district)
    VALUES ('$name','$age','$localchurch','$district')";
    $r = mysql_query($sql);
    if(!$r) {

    $err=mysql_error();

    print $err;

    exit();}
    $mysql_close($db);



    }
    }

    else if($action== inq)

    {
    $link=mysql_connect("localhost", "root", "jya0312@") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql = "SELECT event,location,time from activity";
    while($r = mysql_fetch_array($sql)){
    $items[] = array('event'=>$r['event'],
    'location'=>$r['location'],
    'date'=>$r['date']);
    }
    return $items;


    $mysql_close($link);


    }





    return $list;

    }

    My problem is the logic behind to select either registration or inquiry via SMS.Which one will be the first to use?My server right now has been deactivated since i am not yet defending my master thesis until next year so what i am doing is to ask some help before i test my system.
    Revised source code:
    Code PHP:
    function globe_receive_sms(){
     $in = file_get_contents("php://input");
     /* temporary storage */
     $list = array();
     
     
     /* available in PHP5 is the DOMDocument class which we can use to parse XML */
     $doc = new DOMDocument();
     
     $doc->loadXML($in);
     
     /* here we just iterate through the XML and store the data points into the $list array */
     $params = $doc->getElementsByTagName("param");
     foreach( $params as $param )
    {
     
     $names = $param->getElementsByTagName("name");
     $name = $names->item(0)->nodeValue;
     
     $values = $param->getElementsByTagName("value");
     $value = $values->item(0)->nodeValue;
     
     $list[$name] = mysql_escape_string($value);
     list($action, $name, $age, $localchurch, $district)=explode(" ",$list);
     list($action, $event,$location,$time) = explode("     ",$list); 
     if ($action=='reg')
    {
    $db=mysql_connect("localhost", "*****", "******") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql="INSERT INTO mydb (name,age,localchurch,district) 
    VALUES ('$name','$age','$localchurch','$district')";
    $r = mysql_query($sql);
    if(!$r) {
     
        $err=mysql_error();
     
        print $err;
     
        exit();}
    $mysql_close($db);
     
     
    }	
    else if ($action=='inq')
     
    {
    $link=mysql_connect("localhost", "****", "*****") or die("Cannot connect to DB!");
    mysql_select_db("cyfdb") or die("Cannot select DB!");
    $sql = "SELECT event,location,time from activity";
    while($r = mysql_fetch_array($sql)){
    	  $items[] = array('event'=>$r['event'],
                              'location'=>$r['location'],
                              'date'=>$r['date']); 
    	}
    	return $items;
     
     
    $mysql_close($link);
     
     
    	}
     
     
     
     
     
     return $list;
     
     }
    }
    Last edited by Mittineague; Dec 12, 2013 at 23:09. Reason: reformatting bbcode tags

  19. #19
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi;
    I have my new project entitled "SMS Notification System".But instead of using a keyword, it will use a question like "what is the current activity today?" then the system will reply message about the current activity.
    I want an answer on this matter as soon as possible.
    Thank you very much.

  20. #20
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my php code in receiving message from the user. I would like to let the user register, inquire and receive updates via SMS.

    php:
    PHP Code:
    <?php
    $json 
    file_get_contents('php://input');
        
    $json stripslashes($json);
        
    $values json_decode($jsontrue);

    Array (
       
    "inboundSMSMessageList" => Array (
           
    "inboundSMSMessage" => Array (
              [
    0] => Array (
                 
    "dateTime" => "Wed February 25 2014 12:12:13 GMT+0000 (UTC)",
                 
    "destinationAddress" => "21587258",
                 
    "messageId" => null,
                 
    "message" => "Hello",
                 
    "resourceURL" => null,
                 
    "senderAddress" => "9152886810"
              
    )
            ),
            
    "numberOfMessagesInThisBatch" => 1,
            
    "resourceURL" => null,
            
    "totalNumberOfPendingMessages" => null
        
    )
    )
    ?>
    I do not know where do i put inside the code.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •