PHP script for 2way

PHP script for 2way SearchSearch
Author Message
Carlos Stirling
New member
Username: Blue

Post Number: 9
Registered: 05-2006
Posted on Thursday, June 29, 2006 - 04:09 pm:   

I need a php script that can do the following things.
When someone send a sms with a word like "Hi".
it needs to count every one.
Send a sms to that person with his number lets say if he is the 7 sms'er he would get somthing like " your the 7 "
When the counter gets to let's say 30 that person would get something like "Congrat your 30"
And reset to 0 and start over.

I'm not that good with php scripting yet.
Carlos Stirling
New member
Username: Blue

Post Number: 10
Registered: 05-2006
Posted on Thursday, June 29, 2006 - 08:59 pm:   

How can I test 2way php script without having to connect to my service provider.
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 6135
Registered: 10-2002
Posted on Thursday, June 29, 2006 - 11:12 pm:   

Hi Carlos,

I don't think there is any easy way ...

But I did offer a suggestion to a similar question in the following thread:

http://support.nowsms.com/discus/messages/1/8670.html

-bn
justme
New member
Username: Justme

Post Number: 6
Registered: 01-2006
Posted on Friday, June 30, 2006 - 10:49 am:   

Carlos,

If i understand your requirements correctly, NowSMS is not the program to do your requests. You will need to use php and a sql (sqlite or mysql).

To my knowledge NowSMS does not do databasing in any form whatsoever.

### THIS IS NOT A WORKING MODEL
### THIS IS JUST AN EXAMPLE / IDEA TO HELP YOU IN THE RIGHT DIRECTION
### THERE ARE MANY (BETTER) WAYS TO DO IT

<?php

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);


## vars form 2way
## eg in 2 way
## http://server/counter.php?MSISDN=@@SENDER@@&TEXT=@@FULLSMS@@&SHORTCODE=@@RECIP@@
##
## in your server logs it would look like
## /counter.php?MSISDN=%2B11223456789&TEXT=HI&SHORTCODE=12345

$text = $_GET['TEXT'];
$msisdn = $_GET['MSISDN'];

##############################################################################
## MAKE A DB CONNECTION SO THE DB WILL REMEMBER WHICH USER(MSISDN) HAS COME IN
## FOR YOUR EXAMPLE WE WILL COUNT THE INCOMINGS PER DAY
##############################################################################

## TABLE STRUCTURE
## id (autoinc)
## date (YYYY-MM-DD)
## time (HH:MM:SS)
## daycounter (int)
## msisdn (varchar)

## CONNECT TO MySQL AND SELECT THE DATABASE TO USE
$link = @mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
@die('Not connected : ' . @mysql_error());
## select db
$db_selected = @mysql_select_db('foo', $link);
if (!$db_selected) {
@die ("Can't use foo : " . @mysql_error());
}
## IF YOU GET HERE YOU HAVE CONNECTED SUCCESSFULLY
## DO SQL QUERY TO SEE HOW MANY TIMES SOMEONE HAS COME IN FOR THE DAY
$today = date('Y-m-d');
$time = date('H:i:s');

$sqlDayCount = "SELECT count(daycount) FROM tableName WHERE date = '$today'";
$qryDayCount = @mysql_query($sqlDayCount) or @die('And the error is ---> '.@mysql_error());
$rowDayCount = @mysql_fetch_row($qryDayCount);

## $rowDayCount will show the amount of entries that has come in for the specific day

## YOU KNOW HOW MANY ENTRIES YOU HAVE HAD
## NOW ADD THE ENTRY TO THE DATABASE AND INCREMENT THE 'DAY COUNTER'
$counter = $rowDayCount + 1;


$sqlAddUser = "INSERT INTO tableName (date, time, daycounter, msisdn) values ('$today', $time, $counter, $msisdn)";
$qryAddUser = @mysql_query($sqlAddUser);

$messageToSMS = "Hi there $MSISDN, you are number $counter for today";

} else {
$messageToSMS = "An error as occured. Please call the helpdesk at 555-biteme";
}





##############################################################################
## MAKE SURE IN NowSMS IN THE 2WAY 'Command returns responce text' IS CHECKED
##############################################################################

## MUST SET THIS FOR NowSMS AS IT TAKES PLAIN TEXT AND RETURNS THAT TO THE USER
## AS A SMS
header('Content-Type: text/plain; charset=UTF-8');
echo $messageToSMS;

exit();

?>
james henchman
New member
Username: Jchman

Post Number: 1
Registered: 07-2006
Posted on Saturday, July 01, 2006 - 09:32 pm:   

how can teach me how to send sms via the internet and also teach me how to upload this sricpt?
text/plainwithit
sms.php (2.6 k)
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 6149
Registered: 10-2002
Posted on Monday, July 03, 2006 - 03:26 pm:   

The scripts referenced above are for use with NowSMS.

(As justme mentions, NowSMS does not do any direct interfacing with databases ... but it can call scripts which do this type of interface. Everybody's database is different.)

If you are confused about what NowSMS is, please see http://www.nowsms.com/whatisnowsms.htm.