How to Receive a Message from the Web through ODBC Connection

This sample demonstrates how receive a message from the web through ODBC connection.

Files used in this sample are located in the folder:

    C:\Program Files\CodeSegment\SMS Studio\Samples\ODBCConnection

The contents of the receive_sms.asp file:

<%
'-------------------------------------------------------------------------------------------------------------------------------
' This script inserts a message into the database.
' WARNING: Error checking omitted for clarity.
' However, the remote computer will get the Ok response only after successful reception of a message.
'-------------------------------------------------------------------------------------------------------------------------------

AllowedIP = "127.0.0.1"                           ' Put the IP address of the remote computer allowed to send you messages
RemoteIP = Request.ServerVariables("REMOTE_ADDR") ' Take the address of the remote computer which tries to send you this message
RemoteIP = AllowedIP                              ' Delete or comment this line to enable the simple IP check

if RemoteIP = AllowedIP then
   
    MsgText = Replace(Request("msg"),"'","''")    ' A quote character may render an SQL query invalid
    Sender = Replace(Request("from"),"'","''")
    Recipient = Replace(Request("to"),"'","''")
   
    set database = Server.CreateObject("ADODB.Connection")
    database.Open "SMS ODBC Database"
   
    database.Execute "INSERT INTO Incoming (RefID, MsgText, MsgType, Sender, Recipient) VALUES (0,'" & MsgText & "',0,'" & Sender & "','" & Recipient & "')"
   
    database.Close
   
    response.write("Ok")                          ' This line will not be executed in case of the failure
   
else
   
    response.write("Not allowed.")                ' Our simple IP check detected not allowed access
   
end if

'-------------------------------------------------------------------------------------------------------------------------------
' Copyright (c) 2002-2006 CodeSegment. All rights reserved.                                          http://www.codesegment.com/
'-------------------------------------------------------------------------------------------------------------------------------
%>

How to run this sample

  1. See How to Setup an ODBC Connection to setup an ODBC connection.
  2. Install a web server on your computer. See How to Setup a Web Server for detailed instructions.
  3. Copy the receive_sms.asp and test_receive_sms.htm files to a folder accessible by your web server (e.g. C:\Inetpub\wwwroot\smsstudio).
  4. To test receiving on your computer, use the following link:
    http://localhost/smsstudio/test_receive_sms.htm.
    Fill in the fields and click the Submit button. You should see the confirmation page in your browser. Check the Inbox window in SMS Studio to see that the message has arrived.
  5. To test receiving from a remote location, use the following link:
    http://YOUR_DOMAIN_NAME_OR_IP_ADDRESS/smsstudio/test_receive_sms.htm
  6. You can now inform your client to send you messages by using the following syntax:
    http://YOUR_DOMAIN_NAME_OR_IP_ADDRESS/smsstudio/receive_sms.asp?from=SENDER&to=RECIPIENT&msg=MESSAGE_TEXT

Related topics

ODBC Account

 

Copyright © 2002-2007 CodeSegment. All rights reserved.

   www.codesegment.com