Jump to content

Script is sending multiple sms in application


winsam

Recommended Posts

When the script executes, it sends the sms multiple times.  I don't know which variable to change for it to search the database once and then send out the message. This script was built for me and I modified it to change some variables.
 
        
 
I am very new to php
 
This is the first script, second is below
 
<?php

function responseMessage($message) {
   $xml = new SimpleXMLElement('<Response/>');
   if(is_array($message)) {
      
      $pageNow = isset($_GET["page"]) ? $_GET["page"] : 0;
      $limit = 1000;
      $doneRedirect = false;
      
      if(count($message) > 5) {
            $limit = ($pageNow * 5) + 5;
      }
      
      $i = 0;
      foreach($message as $msg) {
         if($msg != "" && $msg != null && strlen($msg) > 10 && !is_array($msg)) {
            $i++;
            if($i < $limit && $i >= ($pageNow * 5)) {
                $xml->addChild('Message', str_replace('&', "and", $msg));
            }
            else if(!$doneRedirect && $i >= ($pageNow * 5)) {
                $doneRedirect = true;
                $xml->addChild('Redirect', "/TwilioSMS.php?page=" . ($pageNow + 1));
            }
         }
      }
   }
   else {
      $xml->addChild('Message', $message);
   }

/*   $dom = new DOMDocument();
   $dom->loadXML($xml->asXML());
   $dom->formatOutput = true;
   $formattedXML = $dom->saveXML();*/
   
   return $xml->asXML();
}

function splitMessages($message) {
   $ar = explode("-/-/newline/-/-", wordwrap($message, 155, "-/-/newline/-/-", false));
//   array_pop($ar);
   return $ar;
}

function startsWith($haystack, $needle) {
   return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}

function checkKeyword($str, $arr) {
   foreach($arr as $srch) {
      if(startsWith($str, $srch)) {
         return $srch;
      }
   }
   return null;
}

$from = $_POST["From"];
$to = $_POST["To"];
$body = (isset($_POST["Body"])) ? strtolower($_POST["Body"]) : $_GET["Body"];

$_CONFIG["mysql.host"] = "localhost";
$_CONFIG["mysql.username"] = "
$_CONFIG["mysql.password"]
$_CONFIG["mysql.database"] = "

$con = mysqli_connect($_CONFIG["mysql.host"], $_CONFIG["mysql.username"], $_CONFIG["mysql.password"], $_CONFIG["mysql.database"]);

if(!$con) {
   die("Unable to connect to SQL: " . mysqli_error($con));
}

/*if($from == "" || $to == "" || $body == "") {
   die("Invalid params");
}*/

$top = checkKeyword($body, array("top", "top 10", "top10"));
$ubra = checkKeyword($body, array("ubra","UBRA","Ubra"));
$all = checkKeyword($body, array("all"));
$fast = checkKeyword($body, array("fast"));
$draw = checkKeyword($body, array("draw"));
$horse = checkKeyword($body, array("get horse", "search horse"));
$rider = checkKeyword($body, array("get rider", "search rider"));
$welcome = checkKeyword($body, array("result", "results"));

if($welcome != "") {
   $output[] = "Welcome! Text\nTOP for D's\nFAST for Fastest Times\nDRAW 150 for draw #150\nGET RIDER (NAME) for draw # & results of rider\nGET HORSE (NAME) for draw # & results of horse\nSTOP to unsubcribe\nMsg & data rates may apply";
}
else if($top != "") {
   include("keywords/top.php");
}
else if($ubra != "") {
   include("keywords/ubra.php");
}
else if($all != "") {
   include("keywords/all.php");
}
else if($fast != "") {
   include("keywords/fast.php");
}
else if($draw != "" || is_numeric($body)) {
   include("keywords/draw.php");
}
else if($horse != "") {
   include("keywords/horse.php");
}
else if($rider != "" || ($body != "" && strlen($body) >= 3)) {
   include("keywords/rider.php");
}

header("Content-type: text/xml");
echo responseMessage($output);
 
This is the rider script - the only thing i'm using right now
 
<?php

$extra = "";

$search = mysqli_real_escape_string($con, substr($body, strlen($draw)));

$output = array();

$query = mysqli_query($con, "SELECT * FROM (SELECT *, MATCH(rider) AGAINST('*$search*' IN BOOLEAN MODE) AS score FROM `draws`) AS T WHERE score > 0 ORDER BY score DESC LIMIT 10");
while($row = mysqli_fetch_assoc($query))
{
    $info .= "" . $row["rider"] . " ";
    $info .= "" . $row["horse"] . "\n";
    $info .= "" . $row["run_time"] . "\n";
 
    
    
    
    $output[] = $info;

Edited by winsam
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.