Miscellaneous

  Home arrow Miscellaneous arrow Page 5 - Sending SMS Thru HTTP
MISCELLANEOUS

Sending SMS Thru HTTP
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 64
    2005-05-11

    Table of Contents:
  • Sending SMS Thru HTTP
  • Understanding the Requirements of the Gateway
  • Prepare the Request
  • Sending the request with CURL
  • Sending the Request with Sockets
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Sending SMS Thru HTTP - Sending the Request with Sockets


    (Page 5 of 6 )

    CURL functions depend on an external library and PHP must have been compiled with the --with-curl flag. So while CURL is very flexible and useful, it may not be available with your PHP installation. If this is the case, you can still communicate with the SMS gateway using sockets.

    <?php
    //First prepare the info that relates to the connection
    $host "tm4b.com";
    $script "/client/api/send.php";
    $request_length strlen($request);
    $method "POST"// must be POST if sending multiple messages
    if ($method == "GET"
    {
      
    $script .= "?$request";
    }

    //Now comes the header which we are going to post. 
    $header "$method $script HTTP/1.1\r\n";
    $header .= "Host: $host\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: $request_length\r\n";
    $header .= "Connection: close\r\n\r\n";
    $header .= "$request\r\n";

    //Now we open up the connection
    $socket = @fsockopen($host80$errno$errstr); 
    if (
    $socket//if its open, then...

      
    fputs($socket$header); // send the details over
      
    while(!feof($socket))
      {
        
    $output[] = fgets($socket); //get the results 
      
    }
      
    fclose($socket); 


    /* the message id's will be kept in one of the $output values
    print "&lt;pre&gt;";
    print_r($output);
    print "&lt;/pre&gt;";
    */
    ?>

    First we layout the information we'll need to send our SMS and use it construct the HTTP header. A socket connection is established to our gateway using fsockopen. Information is sent and received in the same manner PHP would read and write to a file. After our transfer is complete we close the socket using fclose.

    More Miscellaneous Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap