Miscellaneous Code
  Home arrow Miscellaneous Code arrow 2-way SMS/EMS/Ringtone/Logo script
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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 CODE

2-way SMS/EMS/Ringtone/Logo script
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-06-22

    Table of Contents:

    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


    This script allows you to send SMS (also long SMS), EMS, RTTTL-Ringtones, Logos (GIF, JPG, PNG) with automatic image resizing, EMS Pictures with copy protection and autosave feature, Nokia Operator Logos, Nokia Multipart messages and so on. Pictures and Ringtones can be HEX-included or specified to be downloaded from a HTTP-source. You can setup the 2-way service within minutes on TrueSenses.com. Requires NO additional libraries programs or databases.

    By : simmcomm

    <html>
    <head>
    <title>TrueSenses Response</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php

    /*
    ************************************************************************************
    * 2-way mobile messaging script, (c) 2003 TrueSenses.com - http://www.truesenses.com
    *
    * -> This script allows you to operate a 2-way SMS service and send ringtones, logos
    * -> and much more directly from your site.
    *
    * -> This script does not need any other execution rights like executing sub-
    * -> programs and should therefore run on almost every server supporting PHP.
    *
    * -> For outgoing SMS you will need to have a TrueSenses.com account.
    * -> For incoming SMS you will need to activate the keyword service for as low as
    * -> CHF 5.- (Swiss Francs) per keyword and month including unlimited incoming SMS.
    *
    * You will need to configure $truesenses_account,$truesenses_password and
    * $truesenses_origin
    *
    * This script is pre-configured to act on incoming SMS messages sent by the
    * TrueSenses.com SMS-Gateway. It will compare the incoming keyword and send back
    * the requested content.
    *
    * If you ONLY want to use this script to send messages (without 2-way service),
    * simply modify the MAIN program code to discard the incoming parameters provided
    * by the gateway: $NUMBER (origin number, international format) and $MESSAGE
    *
    * The following message-modes are supported:
    *
    * - SMS
    * - EMS
    * - EMS Images
    * - NOKIA Ringtones
    * - NOKIA Logos
    * - NOKIA Multipart messages (Picture Message with text)
    *
    *
    * In order to install the 2-way SMS script follow these steps:
    *
    *
    * 1. Open an account on TrueSenses.com
    * 2. Configure this script with your Account/Password and upload it to your server
    * 3. Buy some outgoing SMS credits
    * 4. Go to Configuration / Keyword services and add a keyword
    * 4.1 Click on the keyword and activate PUSH to forward incoming SMS to this script
    * example: http://www.[yoursitename].com/truesenses_2way.php
    * method: select POST method - dont forget to click on "Activated"
    * 4.2 Activate the keyword by clicking "Activate keyword"
    * 5. Your service is now up and running
    *
    * Send the following SMS to +41-79 381 60 10 or the number given by TrueSenses.com
    *
    * yourkeyword SMS
    * -> You will receive a SMS back to your phone.
    *
    * yourkeyword SMSFLASH
    * -> You will receive a flashing class 0 SMS back to your phone.
    *
    * yourkeyword NOKIARINGTONE
    * -> You will receive a ringtone for your NOKIA phone, downloaded from HTTP-Source.
    *
    * yourkeyword NOKIARINGTONEHEX
    * -> You will receive a ringtone for your NOKIA phone, included as hex-encoded.
    *
    * yourkeyword NOKIALOGO
    * -> You will receive an operator logo for your NOKIA phone, downloaded from HTTP-
    * -> source. IMPORTANT: configure the mnc and mmc settings first according to the
    * -> destination provider. Otherwise the logo will not show up.
    *
    * yourkeyword NOKIAMULTIPART
    * -> You will receive a picture message with a text for your NOKIA phone, downloaded
    * -> from a HTTP-source.
    *
    * yourkeyword EMSLOGO
    * -> You will receive a picture message for your NON-Nokia phone like SonyEricsson
    * -> and all other vendors who support the EMS-standard on their phones. The image
    * -> is by default copy protected and cannot be sent to another phone. You can de-
    * -> activate this by setting protected = "NO".
    *
    ************************************************************************************
    */




    $truesenses_account = "YourAccountName"; // TrueSenses.com Account-Name
    $truesenses_password = "YourPassword"; // Account-Password
    $truesenses_origin = "TrueSenses"; // Message-Origin, 11 alpha chars or numeric number
    $debug = 0; // debug-output 0 = off, 1 = on


    //
    // open a http-channel, transmit data and return received buffer
    function sendToHost($host,$method,$path,$data,$useragent,$poststr)
    {

    global $debug;

    if (empty($method)) { // default GET
    $method = 'GET';
    }
    $method = strtoupper($method);
    $fp = fsockopen($host, 80, $errno, $errstr, 30);
    if (!$fp) {
    if ($debug == 1) {
    echo("Could not open connection<br>$errstr ($errno)<br>\n");
    }
    } else {
    if ($method == 'GET')
    $path .= '?' . $data;
    fputs($fp, "$method $path HTTP/1.0\r\n");
    fputs($fp, "Host: $host\r\n");
    fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
    if ($method == 'POST') {
    fputs($fp, "Content-Length: " . strlen($data) . "\r\n");
    } else {
    if (strlen($poststr)>0) { // if something to POST on GET method
    fputs($fp, "Content-Length: " . strlen($poststr) . "\r\n");
    }
    }
    if (strlen($useragent)>0) {
    fputs($fp, "User-Agent: $useragent\r\n");
    } else {
    fputs($fp, "User-Agent: TrueSensesPHP\r\n");
    }
    fputs($fp, "Connection: close\r\n");
    fputs($fp, "\r\n");
    if ($method == 'POST') {
    fputs($fp, $data);
    } else { // GET method
    if (strlen($poststr)>0) { // if something to POST on GET method
    fputs($fp, $poststr);
    }
    }

    $buf = "";
    $line = "";
    $chr = "0";
    $contentsize = "0";
    // echo("reading response\n");
    while ((!feof($fp)) && (strlen($buf)<=100000) && ($chr < 500)) { // read max 100000 bytes or 500 lines
    $chr = $chr + 1;
    $line = fgets($fp, 10000); // read one line
    $buf .= $line; // append to buffer
    }

    // sometimes contentsize was not received ...had to replace with part below
    /*
    $contpos = strpos(strtoupper($buf), "CONTENT-LENGTH:");
    if ($contpos > 0) { // determine content size
    if ($debug == 1) {
    echo("decoding content-length<br>\n");
    }
    $contentsize = substr($buf, ($contpos + 16), 20);
    while (strpos($contentsize, "\n") > 0) {
    $contentsize = substr($contentsize, 0, strpos($contentsize, "\n") -1);
    }
    while (strpos($contentsize, "\r") > 0) {
    $contentsize = substr($contentsize, 0, strpos($contentsize, "\r") -1);
    }
    if ($debug == 1) {
    echo("contentsize::$contentsize::<br>\n");
    }
    } else {
    if ($debug == 1) {
    echo("NO contentsize found in ::$buf::<br>\n");
    }
    return "ERROR";
    }
    */

    // replaced above part with this one
    $contpos = strpos(strtoupper($buf), "CONTENT-TYPE");
    if ($contpos > 0) {
    // echo("FOUND contenttype in ::$buf::<br>\n");
    $buf = substr($buf, $contpos, strlen($buf) - $contpos);
    // echo("new buffer::$buf::<br>\n");
    // $buf = substr($buf, strpos($buf, "\n") + 1, strlen($buf) - strpos($buf, "\n"));
    $buf = substr($buf, 27, strlen($buf) - (27 + 1)); // assumes Content-Type: text/html (27 chars)

    } else {
    if ($debug == 1) {
    echo("NO contenttype found in ::$buf::<br>\n");
    }
    return "ERROR";
    }

    // delete everything else than the content from the buffer
    // $buf = substr($buf, (strlen($buf) - $contentsize), $contentsize - 1);

    // echo("buffer::$buf::<br>\n");
    // echo("after response\n");

    fclose($fp);
    return $buf; // return the buffer
    }
    } // sendToHost


    //
    // compose the XML-message ans transfer it to sendToHost
    function sendXML($destination, $origin, $middle)
    {
    global $truesenses_account;
    global $truesenses_password;

    $poststring = "<?xml version=\"1.0\"?>\n";
    $poststring .= "<Message>\n";

    $poststring .= "<Destination>\n";
    $poststring .= "<GSM number=\"$destination\" />\n";
    $poststring .= "</Destination>\n";

    $poststring .= "<ORIGINATOR value=\"$origin\" />\n";

    $poststring .= $middle; // insert middle part here

    $poststring .= "</Message>\n";

    $sendresp = sendToHost('www.truesenses.com','get','/cgi-bin/smsgateway.cgi', "FUNCTION=EXTERN_XMLUPLOAD&ACCOUNT=$truesenses_account&PASSWORD=$truesenses_password", "", "$poststring");

    return $sendresp; // return response

    } // sendXML




    // MAIN program

    // Look if incoming message contains a space (keyword detected)
    //
    // Incoming message will contain the full message (no keyword required) if you
    // are hosting a dedicated access number on TrueSenses
    //
    $pos = strpos ($MESSAGE, " ");

    if ($pos === false) { // no space in message detected, keyword is message
    $KEYWORD = "$MESSAGE";
    $MSGONLY = "$MESSAGE";
    } else { // space detected, extract keyword
    $KEYWORD = substr($MESSAGE, 0, $pos);
    $MSGONLY = substr($MESSAGE, ($pos + 1), (strlen($MESSAGE) - ($pos)));
    }

    if ($debug == 1) {
    echo("Keyword::$KEYWORD:: Msgonly::$MSGONLY:: Fullmessage::$MESSAGE::<br>\n");
    }

    if (strcmp(strtoupper($MSGONLY), "SMS") == 0) {

    // sends a normal SMS

    $xmlmsg = "<SMS encoded=\"YES\">\n";
    // add the following line if you want to send long-SMS (spawning over multiple SMS)
    // $xmlmsg .= "<long />\n";
    $xmlmsg .= "<CONTENT>";
    $xmlmsg .= urlencode("Your keyword was $KEYWORD and your message was $MSGONLY"); // hex-encode the content
    $xmlmsg .= "</CONTENT>\n";
    $xmlmsg .= "</SMS>\n";

    $rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);

    if ($debug == 1) {
    echo("RESPONSE::$rcbuf::\n");
    }
    } // SMS reply

    if (strcmp(strtoupper($MSGONLY), "SMSFLASH") == 0) {

    // sends a flasing SMS

    $xmlmsg = "<SMS encoded=\"YES\">\n";
    $xmlmsg .= "<flashing />\n"; // set msgclass 0 flag
    // add the following line if you want to send long-SMS (spawning over multiple SMS)
    // $xmlmsg .= "<long />\n";
    $xmlmsg .= "<CONTENT>";
    $xmlmsg .= urlencode("Your keyword was $KEYWORD and your message was $MSGONLY"); // hex-encode the content
    $xmlmsg .= "</CONTENT>\n";
    $xmlmsg .= "</SMS>\n";

    $rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);

    if ($debug == 1) {
    echo("RESPONSE::$rcbuf::\n");
    }
    } // SMS reply

    if (strcmp(strtoupper($MSGONLY), "NOKIARINGTONE") == 0) {

    // sends a nokiaringtone - input must be in RTTTL format
    //

    // assemble XML message

    $http_location = "http://www.simmcomm.ch/ringtone.txt"; // location of the ringtone

    $xmlmsg = "<NOKIARINGTONE>\n";
    $xmlmsg .= "<RINGTONE source=\"HTTP\" type=\"RTTTL\">$http_location</RINGTONE>\n";
    $xmlmsg .= "</NOKIARINGTONE>\n";

    $rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);

    if ($debug == 1) {
    echo("RESPONSE::$rcbuf::\n");
    }
    } // NOKIARINGTONE

    if (strcmp(strtoupper($MSGONLY), "NOKIARINGTONEHEX") == 0) {

    // sends a nokiaringtone as hex include - input must be in RTTTL format
    //

    // assemble XML message

    $http_location = urlencode("KnightRider:d=4,o=5,b=125:16e,16p,16f,16e,16e,16p,16e,16e,16f,16e,16e,16e,16d#,16e,16e,16e,16e,16p,16f,16e,16e,16p,16f,16e,16f,16e,16e,16e,16d#,16e,16e,16e,16d,16p,16e,16d,16d,16p,16e,16d,16e,16d,16d,16d,16c,16d,16d,16d,16d,16p,16e,16d,16d,16p,16e,16d,16e,16d,16d,16d,16c,16d,16d,16d"); // free demo ringtone from the internet

    $xmlmsg = "<NOKIARINGTONE>\n";
    $xmlmsg .= "<RINGTONE source=\"BINARY\" type=\"RTTTL\">$http_location</RINGTONE>\n";
    $xmlmsg .= "</NOKIARINGTONE>\n";

    $rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);

    if ($debug == 1) {
    echo("RESPONSE::$rcbuf::\n");
    }
    } // NOKIARINGTONEHEX

    if (strcmp(strtoupper($MSGONLY), "NOKIALOGO") == 0) {

    // sends a nokialogo - input must be in GIF, JPG or PNG
    //
    // parameters:
    // mcc = MobileCountryCode for destination (example 228 - switzerland)
    // mnc = MobileNetworkCode for destination (example 01 - swisscom, 02 sunrise, 03 orange)

    // assemble XML message

    $http_type = "GIF";
    $http_location = "http://www.simmcomm.ch/nokialogo.gif"; // location of the logo

    $destination_mcc = "228"; // mandatory: MobileCountryCode for destination
    $destination_mnc = "01"; // mandatory: MobileNetworkCode for destination


    $xmlmsg = "<NOKIALOGO mcc=\"$destination_mcc\" mnc=\"$destination_mnc\">\n";
    $xmlmsg .= "<IMAGE source=\"HTTP\" type=\"$http_type\">$http_location</IMAGE>\n";
    $xmlmsg .= "</NOKIALOGO>\n";

    $rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);

    if ($debug == 1) {
    echo("RESPONSE::$rcbuf::\n");
    }
    } // NOKIALOGO

    if (strcmp(strtoupper($MSGONLY), "NOKIAMULTIPART") == 0) {

    // sends a nokiamultipart message (picturemessage) - input must be in GIF, JPG or PNG
    //
    // options:
    // - specify <CONTENT> tag if you want to send some text with your image

    // assemble XML message

    $http_type = "GIF";
    $http_location = "http://www.simmcomm.ch/nokialogo.gif"; // location of the logo


    $xmlmsg = "<NOKIAMULTIPART encoded=\"YES\">\n";
    $xmlmsg .= "<IMAGE source=\"HTTP\" type=\"$http_type\">$http_location</IMAGE>\n";
    $xmlmsg .= "<CONTENT>";
    $xmlmsg .= urlencode("Your logo"); // hex-encode the content
    $xmlmsg .="</CONTENT>\n";
    $xmlmsg .= "</NOKIAMULTIPART>\n";

    $rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);

    if ($debug == 1) {
    echo("RESPONSE::$rcbuf::\n");
    }
    } // NOKIAMULTIPART

    if (strcmp(strtoupper($MSGONLY), "EMSLOGO") == 0) {

    // sends a logo to NON-nokia, EMS-capable phones like SonyEricsson
    //
    // parameters:
    // autosave = YES/NO (automatically ask user to save image)
    // protected = YES/NO (disallow re-distribution of image)
    // width = x (width of image, do not provide parameter for autosizing)
    // height = y (height of image, do not provide parameter for autosizing)

    // assemble XML message

    $http_type = "GIF";
    $http_location = "http://www.simmcomm.ch/nokialogo.gif"; // location of the logo

    $xmlmsg = "<EMS>\n";
    // no newline after <content> tag as it would convert to text-enter %0A in ems and would consume space
    $xmlmsg .= "<CONTENT><IMAGE source=\"HTTP\" type=\"$http_type\" autosave=\"YES\" protected=\"NO\">$http_location</IMAGE></CONTENT>\n";
    $xmlmsg .= "</EMS>\n";

    $rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);

    if ($debug == 1) {
    echo("RESPONSE::$rcbuf::\n");
    }
    } // EMSLOGO

    // send confirmation to TrueSenses.com that we have received the incoming sms

    echo("OK<br>\n");
    ?>
    </body>
    </html>

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    IBM DB2 Deep Compression ROI Tool

    The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times.
    FREE! Go There Now!


    NEW! Rational Talks to You:Per Kroll on Rational Method Composer Plug-in customization

    Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Webcast: Calling All Testers! Find Application Vulnerabilities Early in the Development Process Where they are Easier to Fix and Less Risky to your Business

    In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek