Miscellaneous
  Home arrow Miscellaneous arrow Page 35 - Sending SMS Thru HTTP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Sending SMS Thru HTTP
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 35
    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
  • Introduction
  • Understanding the Requirements of the Gateway
  • Prepare the Request
  • Sending the request with CURL
  • Sending the Request with Sockets
  • Conclusion
  • Introduction
  • Understanding the Requirements of the Gateway
  • Prepare the Request
  • Sending the request with CURL
  • Sending the Request with Sockets
  • Conclusion
  • Introduction
  • Understanding the Requirements of the Gateway
  • Prepare the Request
  • Sending the request with CURL
  • Sending the Request with Sockets
  • Conclusion
  • Introduction
  • Understanding the Requirements of the Gateway
  • Prepare the Request
  • Sending the request with CURL
  • Sending the Request with Sockets
  • Conclusion
  • Introduction
  • Understanding the Requirements of the Gateway
  • Prepare the Request
  • Sending the request with CURL
  • Sending the Request with Sockets
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Sending SMS Thru HTTP - Sending the Request with Sockets


    (Page 35 of 36 )

    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


       · You can use the http_build_query() function instead of using the foreach loop by...
       · When sending request using sockets, you set the $method variable to...
       · With regards to http_build_query, sounds interesting! I'd like to give it a go when...
       · Thanks for the comment.Basically, you can replace &quot;POST&quot; with...
       · If I want to set up a system that is to send texts to individuals in different...
       · You'll find that all SMS Gateways require you to pass them the telephone numbers of...
       · To avoid encoded chunks, use HTTP 1.0.
       · Have you tried it? Does it work?
       · Chunked transfer-encoding was introduced in HTTP 1.1. The only mention of...
       · thank u for ur good work !!!
       · for Philippines, China, Japan, Hong Kong, Indonesia, Thailand, Singapore and...
       · salam! ki&amp;#351;i iki g&uuml;nd&uuml;r senin mailini...
       · salam! ki&amp;#351;i iki g&uuml;nd&uuml;r senin mailini...
       · Hy.... can anyone help me with this script. I can't help myself. Can anyone send me...
       · 
       · gjmbnmbbbnm
       · With the new api you need to change a few params..you need add...
       · sir first time try to this option isnot success but mail server option is vary...
       · I read through the tutorial, and I am a little confused on how the pieces of code...
       · here is another very simple worldwide SMS gateway....
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway