Jump to content

winsam

New Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by winsam

  1. 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;

×
×
  • 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.