Jump to content

cobusbo

Members
  • Posts

    224
  • Joined

  • Last visited

Posts posted by cobusbo

  1. It's still telling you that the MySQL handle is invalid. You need to check the results of each of the connect, db select, query calls BEFORE trying to use them to count the rows returned, to retrieve the data returned, etc.

     

    Check your syntax against what the manual tells you to use. The manual is your friend. Use it.

    Well am I on the right way because what I'm trying to do is to 

     

     

    check in the table named Users for for the field named mxitid if its = to $mxitid field and if its true to recall the value in the in the Username field of the table?

     

    so basicly I want to 

    //Check datababase
    if mxitid in db - $mxitid
    
    if (its true) {
    
    show chat page
    
    with line 207 $name = the username field from the db
    }
    else
    { show login form and script}
    
    
    

    can someone help me with an example please.

  2. Read what the error message is telling you then look at the code on that line.

     

    It says the MySQL link resource is invalid here:

     

    $query0 = mysql_query("SELECT username FROM Users WHERE mxitid=$mid", $con);

     

    So why is it invalid? Look here:

     

    $conn = mysql_connect('*****','*******','*******') or trigger_error("SQL", E_USER_ERROR);

     

    Not difficult.

    Thank you

     

    Stil got the following error

     

     

     

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/page.php on line 31

     

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/page.php on line33

     

    here is the part with the error

    $usernames = $_GET['username'];
    $mid = $_GET['userid'];
    
    $query0 = mysql_query("SELECT username FROM Users WHERE mxitid=$mid", $conn);
    $result99 = mysql_query($query0);
                      if (mysql_num_rows($query0) != 0);
      {
    $list99 = mysql_fetch_assoc($result99);
    
    
  3. Unexpected $end usually means you have a "{" somewhere without a corresponding "}".

     

    You also have some php code amongst your HTML without surrounding <?php..?> tags

    Thanks

     

    now im getting the following error

     

    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/u506124311/public_html/ag/page.php on line 29

     

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/page.php on line 31

     

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/page.php on line 32

    What I'm trying to do is to look up the value in the table named Users in the field mxitid if the user mxit id is the one hes using I want the username he chosen for that specific mxitid to display as the name in line 207

  4.  

    Ok I made a few changes and got the following Parse error

    Here  is my current code

    <?php
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    ?>
    <html><br>
    <b><u>Chat Beta:</u></b>
    
    <br><span style="color:#751919"><b>Welcome to the Chat, </b></span>
    <span style="color:#3f4f5f"><b>
    <?php
    echo
    $_SERVER['HTTP_X_MXIT_NICK'];
    ?></span>
    <br><span style="color:#828282"><b>
    <?php echo date('D H:i:s'); ?></b></span>
    <br><b>NO MODERATION SPOTS OPEN YET!</b>
    <br><a href="page.php">Refresh</a>
    </html>
    <?
    // database connection info
    $conn = mysql_connect('*****','*******','*******') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('*********',$conn) or trigger_error("SQL", E_USER_ERROR);
    ///////////////////////////////////////////
    
    
    $query0 = mysql_query("SELECT username FROM Users WHERE mxitid=$mid", $con);
    $result = mysql_query($query0);
                    $myrows = mysql_fetch_array($result);
      if (mysql_num_rows($query0) != 0)
      {
    ////////////////////////////////////////////
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM StringyChat";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 20;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    
    
    
        /*
         * StringyChat
         *
    	 * Please refer to readme.txt supplied with the StringyChat distribution for information on
    	 * installing and configuring. 
    	 *
         */
    
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    
        include("chat_code_header.php");
    
        $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); 
        $myrow = mysql_fetch_array($result); 
    
        $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on
    	$install_url = $myrow["install_url"]; // URL to install dir of StringyChat
        $name_size = $myrow["name_size"]; // Maximum size of the name
        $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit.
        $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split.
        $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display.
        $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes
    	$email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to
    
        
    	if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) 
        { 
        $StringyChat_name = $_POST['StringyChat_name'];
        $StringyChat_message = $_POST['StringyChat_message'];
        }
    	
    ?>
    
    echo '<div id="StringyChat">';
    
    <?
        // Check if visitor's IP is banned.  If so, do not display the form,
        // show a banned IP message instead.
    
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    if(!isset($name))
    {
    	$name = "SYSOP";
    }
    
    
    
    
        $ip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    if(!isset($ip))
    {
    	$ip = "Debater";
    }
    
    
        $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\"";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        if($myrow["ip"] == "") {	// Checks if IP not found in banned list
    
    
    
    
    ?>
    <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>">
          <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20">
          <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea>
          <br>
          <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message">
        </form>
    </html>
    
    <?
    
        } else {
          echo "<span style='color:#10ce59'><u>Dear User, you have been banned from the Chat due to not following the rules. You will need to come back regularly to see if you were unbanned. Until then, goodbye!</u></span><br>";
        }
        
        // Should we try to create a post?
        if (isset($StringyChat_name) && isset($StringyChat_message)) {
    
            // Remove whitespaces and slashes.
            $name = trim(stripslashes($StringyChat_name));
            $message = trim(stripslashes($StringyChat_message));
    
            
                // Check name and message have been entered.
                if (strlen($name) > 0 && strlen($message) > 0) {
                    
                    // Limit the size of the fields as per variable defnitions.
                    if (strlen($name) > $name_size) {
                        $name = substr($name, 0, $name_size);
                    }
                    if (strlen($message) > $message_size) {
                        $message = substr($message, 0, $message_size);
                    }
                    
                    // Remove new lines from name.
                    $name = str_replace("\n", " ", $name);
                    
    				// Stripping out \r's so email formattnig appears correctly.
    				$message = str_replace("\r", "", $message);
    				
    				// Create an email-friendly version of the message.
    				$message_emailable = str_replace("<br>", "\n", $message);
    				$result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
                    while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	              $the_word = $myrow_wordswap["word"];
                      $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable);
                    }
    
                    // Replace the new lines with encoded line breaks for HTML (thanks milahu).
                    $message = str_replace("\n", "c#lb", $message);
    
                    // Use HTML encoding on ame and message so database doesn't misinterpret data.
    	            $name = htmlentities($name);
                    $message = htmlentities($message, ENT_COMPAT);
    				
                    
                    
                    // IP address of submitter and time of post.
    $ip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    if(!isset($ip))
    {
    	$ip = "Debater";
    }
    
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"];
    $testip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    
    
    if(!isset($mxitid))
    {
    	$mxitid = "DEFAULT";
    
    }
    if(!isset($name))
    {
    	$name = "Debater";
    }
    if ($testip == "m70141099002") {
        $name = "Admin";
    }
    
    
    
    
                    // check to see if a duplicate exists
                    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 30 )";
                    $result = mysql_query($sql);
                    $myrow = mysql_fetch_array($result);
    
                    if($myrow["StringyChat_message"] == "") {	// Checks if record not matching in db
                      // Save the record
                      $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time,mxit_id) VALUES (\"$ip\",\"$name\",\"$msg\",\"$post_time\",\"$mxitid\")";
                      $result = mysql_query($sql);
    				  
    				  
    
                    } else {
                      echo "<span style='color:#10ce59'>Duplicate post detected!</span><p>";
                    }                
                }
                else {
                    echo "<span style='color:#10ce59'>You can't send blanks!</span><br><br>";
                }
    
          unset($_POST["StringyChat_name"]);
          unset($_POST["StringyChat_message"]);
          unset($StringyChat_ip);
          unset($StringyChat_name);
          unset($StringyChat_message);
          unset($StringyChat_time);
          unset($mxit_id);
    	 unset($id);
    
        }
        
    // get the info from the db 
    $sql = "SELECT id, StringyChat_time, StringyChat_name, StringyChat_message, StringyChat_ip FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    function filterBadWords($str)
    {
    	
    	
        $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); 
        $replacements = "#~";
        
        while($row = mysql_fetch_assoc($result1))
        {
              $str = eregi_replace($row['word'], str_repeat('#~', strlen($row['word'])), $str);
        }  
        
        return $str;
    }
    
    
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) 
    //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
     {
       // echo data
       //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
    $admin = array('m70141099002' , 'Debater', '27765238453', '');
    $moderator = array('m65795687002', 'm57010835002' , 'm50079252002');
    $pc = array('');
    $helper = array('' , '');
    $globalhelper = array('');
    $id = $list["id"];
    $nname = $list["StringyChat_name"];
    
    $ipi = $list["StringyChat_ip"];
    $form = '<a href="http://imagecrab.freeserver.me/ag/ban.php?id=' . $id . '&ip=' . $ipi . '&nname=' . $nname .'"> [M] </a>';
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    $testip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    
    if(!isset($name))
    {
    	$name = "Debater";
    }
    
    
    if(!isset($testip))
    {
    	$testip = "Debater";
    }
    
    
    
    if (in_array($testip, $admin))
    {
    if (in_array($list['StringyChat_ip'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  ' ' . '</span>'. '<span style="color:red">' . '<b>'   . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    elseif (in_array($list['StringyChat_ip'], $moderator))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:green">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    elseif (in_array($list['StringyChat_ip'], $pc))
    
    {
       print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:purple">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    elseif (in_array($list['StringyChat_ip'], $helper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    
    elseif (in_array($list['StringyChat_ip'], $globalhelper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:#0365B8">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords($list['StringyChat_message']) .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    }
    }
    
    elseif (in_array($testip, $moderator ))
    {
    if (in_array($list['StringyChat_ip'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  ' ' . '</span>'. '<span style="color:red">' . '<b>'   . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $moderator))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:green">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $pc))
    
    {
       print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:purple">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $helper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    
    elseif (in_array($list['StringyChat_ip'], $globalhelper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:#0365B8">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />';
    }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    else
    {if (in_array($list['StringyChat_ip'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '</span>'. '<span style="color:red">' . '<b>'   . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $moderator))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:green">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $pc))
    
    {
       print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:purple">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $helper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    
    elseif (in_array($list['StringyChat_ip'], $globalhelper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:#0365B8">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />';
    }
    
    }
    
    
    
    }
    
    
    
    
    
    
        // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
        $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db);
    
        include("sort_widths.php");
    
        while ($myrow = mysql_fetch_array($result)) {
          $msg = $myrow["StringyChat_message"];
    	  
    	  // Convert the encoded line break into an actual <br> tag (thanks milahu)
          $msg = str_replace("c#lb", "<br>", $msg);
    
          // Convert the encoded image tag into a html tag
          $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg);
    	  
    	  // split the lines
          $msg = htmlwrap($msg, $line_length);
    
          $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
          while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	    $the_word = $myrow_wordswap["word"];
            $msg = ereg_replace($the_word, ":-x",$msg);
          }
    
       
        }
       ?>     
    <?
    
    
    
    
    
    
    
    
    
    // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    
    ?><br>
    <html>    <span style="color:#828282"><i>Type Your Message NOW!</i></span>
    	<p><a href="page.php">Refresh</a>
    	<br><a href="http://imagecrab.webatu.com/try/index.php">Home</a> | <a 
    	</html>
    
     }
    
      else
      {
        <html>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
    Username:<br>
    <input type="text" name="username" ><br>
    <input type="hidden" value="<?php echo $_SERVER['HTTP_X_MXIT_LOGIN']; ?>" name"userid" >
    
    <br><br>
    <input type="submit" value="Submit">
    </form>
    </html>
    
    <?
    $usernames = $_GET['username'];
    $mid = $_GET['userid'];
    
    $sql0 = "INSERT INTO Users (username,mxitid) VALUES (\"$usernames\",\"$mid\")";
                      $result = mysql_query($sql0);
    
    
    ?>
      }
    

    Ok I changed the following part

    <?
    $usernames = $_GET['username'];
    $mid = $_GET['userid'];
    
    $sql0 = "INSERT INTO Users (username,mxitid) VALUES (\"$usernames\",\"$mid\")";
                      $result = mysql_query($sql0);
    
    
    ?>
      }
    

    to 

    if ($_POST["submit"]) {
    
    $usernames = $_GET['username'];
    $mid = $_GET['userid'];
    
    $sql0 = "INSERT INTO Users (username,mxitid) VALUES (\"$usernames\",\"$mid\")";
                      $result = mysql_query($sql0);
    
    }
    
    

    but still the same error

  5. Only skimmed through the code but I found these issues.

     

    On Line 11 you have an malformed echo statement. Which is not needed.

     

    On line 16 you need to escape the double quotes within your double quoted string

     

    On line 98 you have placed some random HTML. It needs to be echoed

    Ok I made a few changes and got the following Parse error

     

     

    Parse error: syntax error, unexpected $end in /home/u506124311/public_html/ag/page.php on line 569

    Here  is my current code

    <?php
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    ?>
    <html><br>
    <b><u>Chat Beta:</u></b>
    
    <br><span style="color:#751919"><b>Welcome to the Chat, </b></span>
    <span style="color:#3f4f5f"><b>
    <?php
    echo
    $_SERVER['HTTP_X_MXIT_NICK'];
    ?></span>
    <br><span style="color:#828282"><b>
    <?php echo date('D H:i:s'); ?></b></span>
    <br><b>NO MODERATION SPOTS OPEN YET!</b>
    <br><a href="page.php">Refresh</a>
    </html>
    <?
    // database connection info
    $conn = mysql_connect('*****','*******','*******') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('*********',$conn) or trigger_error("SQL", E_USER_ERROR);
    ///////////////////////////////////////////
    
    
    $query0 = mysql_query("SELECT username FROM Users WHERE mxitid=$mid", $con);
    $result = mysql_query($query0);
                    $myrows = mysql_fetch_array($result);
      if (mysql_num_rows($query0) != 0)
      {
    ////////////////////////////////////////////
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM StringyChat";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 20;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    
    
    
        /*
         * StringyChat
         *
    	 * Please refer to readme.txt supplied with the StringyChat distribution for information on
    	 * installing and configuring. 
    	 *
         */
    
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    
        include("chat_code_header.php");
    
        $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); 
        $myrow = mysql_fetch_array($result); 
    
        $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on
    	$install_url = $myrow["install_url"]; // URL to install dir of StringyChat
        $name_size = $myrow["name_size"]; // Maximum size of the name
        $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit.
        $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split.
        $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display.
        $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes
    	$email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to
    
        
    	if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) 
        { 
        $StringyChat_name = $_POST['StringyChat_name'];
        $StringyChat_message = $_POST['StringyChat_message'];
        }
    	
    ?>
    
    echo '<div id="StringyChat">';
    
    <?
        // Check if visitor's IP is banned.  If so, do not display the form,
        // show a banned IP message instead.
    
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    if(!isset($name))
    {
    	$name = "SYSOP";
    }
    
    
    
    
        $ip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    if(!isset($ip))
    {
    	$ip = "Debater";
    }
    
    
        $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\"";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        if($myrow["ip"] == "") {	// Checks if IP not found in banned list
    
    
    
    
    ?>
    <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>">
          <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20">
          <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea>
          <br>
          <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message">
        </form>
    </html>
    
    <?
    
        } else {
          echo "<span style='color:#10ce59'><u>Dear User, you have been banned from the Chat due to not following the rules. You will need to come back regularly to see if you were unbanned. Until then, goodbye!</u></span><br>";
        }
        
        // Should we try to create a post?
        if (isset($StringyChat_name) && isset($StringyChat_message)) {
    
            // Remove whitespaces and slashes.
            $name = trim(stripslashes($StringyChat_name));
            $message = trim(stripslashes($StringyChat_message));
    
            
                // Check name and message have been entered.
                if (strlen($name) > 0 && strlen($message) > 0) {
                    
                    // Limit the size of the fields as per variable defnitions.
                    if (strlen($name) > $name_size) {
                        $name = substr($name, 0, $name_size);
                    }
                    if (strlen($message) > $message_size) {
                        $message = substr($message, 0, $message_size);
                    }
                    
                    // Remove new lines from name.
                    $name = str_replace("\n", " ", $name);
                    
    				// Stripping out \r's so email formattnig appears correctly.
    				$message = str_replace("\r", "", $message);
    				
    				// Create an email-friendly version of the message.
    				$message_emailable = str_replace("<br>", "\n", $message);
    				$result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
                    while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	              $the_word = $myrow_wordswap["word"];
                      $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable);
                    }
    
                    // Replace the new lines with encoded line breaks for HTML (thanks milahu).
                    $message = str_replace("\n", "c#lb", $message);
    
                    // Use HTML encoding on ame and message so database doesn't misinterpret data.
    	            $name = htmlentities($name);
                    $message = htmlentities($message, ENT_COMPAT);
    				
                    
                    
                    // IP address of submitter and time of post.
    $ip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    if(!isset($ip))
    {
    	$ip = "Debater";
    }
    
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"];
    $testip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    
    
    if(!isset($mxitid))
    {
    	$mxitid = "DEFAULT";
    
    }
    if(!isset($name))
    {
    	$name = "Debater";
    }
    if ($testip == "m70141099002") {
        $name = "Admin";
    }
    
    
    
    
                    // check to see if a duplicate exists
                    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 30 )";
                    $result = mysql_query($sql);
                    $myrow = mysql_fetch_array($result);
    
                    if($myrow["StringyChat_message"] == "") {	// Checks if record not matching in db
                      // Save the record
                      $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time,mxit_id) VALUES (\"$ip\",\"$name\",\"$msg\",\"$post_time\",\"$mxitid\")";
                      $result = mysql_query($sql);
    				  
    				  
    
                    } else {
                      echo "<span style='color:#10ce59'>Duplicate post detected!</span><p>";
                    }                
                }
                else {
                    echo "<span style='color:#10ce59'>You can't send blanks!</span><br><br>";
                }
    
          unset($_POST["StringyChat_name"]);
          unset($_POST["StringyChat_message"]);
          unset($StringyChat_ip);
          unset($StringyChat_name);
          unset($StringyChat_message);
          unset($StringyChat_time);
          unset($mxit_id);
    	 unset($id);
    
        }
        
    // get the info from the db 
    $sql = "SELECT id, StringyChat_time, StringyChat_name, StringyChat_message, StringyChat_ip FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    function filterBadWords($str)
    {
    	
    	
        $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); 
        $replacements = "#~";
        
        while($row = mysql_fetch_assoc($result1))
        {
              $str = eregi_replace($row['word'], str_repeat('#~', strlen($row['word'])), $str);
        }  
        
        return $str;
    }
    
    
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) 
    //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
     {
       // echo data
       //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
    $admin = array('m70141099002' , 'Debater', '27765238453', '');
    $moderator = array('m65795687002', 'm57010835002' , 'm50079252002');
    $pc = array('');
    $helper = array('' , '');
    $globalhelper = array('');
    $id = $list["id"];
    $nname = $list["StringyChat_name"];
    
    $ipi = $list["StringyChat_ip"];
    $form = '<a href="http://imagecrab.freeserver.me/ag/ban.php?id=' . $id . '&ip=' . $ipi . '&nname=' . $nname .'"> [M] </a>';
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    $testip = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    
    if(!isset($name))
    {
    	$name = "Debater";
    }
    
    
    if(!isset($testip))
    {
    	$testip = "Debater";
    }
    
    
    
    if (in_array($testip, $admin))
    {
    if (in_array($list['StringyChat_ip'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  ' ' . '</span>'. '<span style="color:red">' . '<b>'   . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    elseif (in_array($list['StringyChat_ip'], $moderator))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:green">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    elseif (in_array($list['StringyChat_ip'], $pc))
    
    {
       print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:purple">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    elseif (in_array($list['StringyChat_ip'], $helper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    
    elseif (in_array($list['StringyChat_ip'], $globalhelper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:#0365B8">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords($list['StringyChat_message']) .  '<span style="color:#d8d8d8">'  . " - " . $ipi . '</span>' . '<br />';
    }
    }
    
    elseif (in_array($testip, $moderator ))
    {
    if (in_array($list['StringyChat_ip'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  ' ' . '</span>'. '<span style="color:red">' . '<b>'   . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $moderator))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:green">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $pc))
    
    {
       print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:purple">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $helper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    
    elseif (in_array($list['StringyChat_ip'], $globalhelper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . $form .  '<span style="color:#0365B8">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />';
    }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    else
    {if (in_array($list['StringyChat_ip'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '</span>'. '<span style="color:red">' . '<b>'   . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $moderator))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:green">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $pc))
    
    {
       print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:purple">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    elseif (in_array($list['StringyChat_ip'], $helper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    
    elseif (in_array($list['StringyChat_ip'], $globalhelper))
    
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:blue">' .  '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />';
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:#0365B8">' .  '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />';
    }
    
    }
    
    
    
    }
    
    
    
    
    
    
        // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
        $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db);
    
        include("sort_widths.php");
    
        while ($myrow = mysql_fetch_array($result)) {
          $msg = $myrow["StringyChat_message"];
    	  
    	  // Convert the encoded line break into an actual <br> tag (thanks milahu)
          $msg = str_replace("c#lb", "<br>", $msg);
    
          // Convert the encoded image tag into a html tag
          $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg);
    	  
    	  // split the lines
          $msg = htmlwrap($msg, $line_length);
    
          $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
          while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	    $the_word = $myrow_wordswap["word"];
            $msg = ereg_replace($the_word, ":-x",$msg);
          }
    
       
        }
       ?>     
    <?
    
    
    
    
    
    
    
    
    
    // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    
    ?><br>
    <html>    <span style="color:#828282"><i>Type Your Message NOW!</i></span>
    	<p><a href="page.php">Refresh</a>
    	<br><a href="http://imagecrab.webatu.com/try/index.php">Home</a> | <a 
    	</html>
    
     }
    
      else
      {
        <html>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
    Username:<br>
    <input type="text" name="username" ><br>
    <input type="hidden" value="<?php echo $_SERVER['HTTP_X_MXIT_LOGIN']; ?>" name"userid" >
    
    <br><br>
    <input type="submit" value="Submit">
    </form>
    </html>
    
    <?
    $usernames = $_GET['username'];
    $mid = $_GET['userid'];
    
    $sql0 = "INSERT INTO Users (username,mxitid) VALUES (\"$usernames\",\"$mid\")";
                      $result = mysql_query($sql0);
    
    
    ?>
      }
    
  6. Well if you replaced the whole of my code with yours then I cannot even know what it is doing now, let alone take any responsibility for it.

    Well what I'm trying to do is, my unique.csv file got like 1000 people listed, but I can only send a list of 50 people each time because the API I use can only support 50 names each time. So what im trying to do is split the list up in 50  so that it sends a batch of 50 messages and then send the next 50 till the total list is done. I've made my batchsize 2 to test it and only the first 2 people on my list got the message the other 998 people didnt. Here is the code I currently got

    <?php
    $visitor = $_GET["visitor"];
    
    	$f_pointer=fopen($visitor,"r"); // file pointer
    $users = array();
    while ($ar=fgetcsv($f_pointer)) {
        if ($ar[0] != '') $users[] = $ar[0]; //only store line in new array if it contains something
    }
    fclose ($f_pointer);
    
    $batchSize = 2;                          // set size of your batches
    
    $batches = array_chunk($users, $batchSize);
    
    foreach ($batches as $batch) {
        $list = join(',', $batch);
        // process the batch list here
    }
    
    require_once ('MxitAPI.php');
    /* Instantiate the Mxit API */
    $key = $_GET["key"];
    $secret = $_GET["secret"];
    $app = $_GET["app"];
    $message = $_GET["message"];
    $api = new MxitAPI($key, $secret);
    $api->get_app_token('message/send');
    $api->send_message($app, $list, $message, 'true');
    echo 'Success';
    ?>
    
    
  7.  

    Ok so I spend some more time with the script and made a few more changes. The options display now but nothing happens when I try to execute them.

    First of all I added the ip to my URL as well

     and made a few changes in my ban.php file like the $_POST changed to $_GET and my form action need to be changed not sure to what.

     

    here is my ban.php file

    <?
    include("admin_code_header.php");
    
    
    if ($_POST["DeletePost"]) {
        $id = $_GET["id"];
        $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
        mysql_query($query);
        echo "ID removed from system: ".$id;
      }
    
    
    if ($_POST["BanIP"]) {
        $IP_To_Add = $_GET["ip"];
        
          $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
          $result = mysql_query($sql);
      }
    
    
    
    ?>
    <html>
    <form name="form" method="post" action="ban.php">
    
    <input name="DeletePost" type="submit" id="DeletePost" value="Delete">
    
    <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $_GET['ip'];?>">
        </form>
    </html>
    
    

     

    Ok so I fixed my script yay

    <?
    $conn = mysql_connect('*********','************','*********') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('*********',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    if ($_POST["DeletePost"]) {
        $id = $HTTP_GET_VARS["id"];
        $query = "DELETE FROM StringyChat WHERE id ='".$id."'"; 
        mysql_query($query);
        echo "ID removed from system: ".$id;
      }
    
    
    if ($_POST["BanIP"]) {
        $IP_To_Add = $HTTP_GET_VARS["ip"];
        
          $sql = "INSERT INTO StringyChat_IPBan (ip) VALUES (\"$IP_To_Add\")";
          $result = mysql_query($sql);
      }
    
    if ($_POST["Unban"]) {
    
    $IP_To_Remove = $HTTP_GET_VARS['ip'];
          $query = "DELETE FROM StringyChat_IPBan WHERE ip ='".$IP_To_Remove."'"; 
          mysql_query($query);
          echo "IP Removed from ban list: ".$IP_To_Remove;
    
      }
    
    
    
    ?>
    <html>
    <form name="form" method="post" action="<? echo $_SERVER['REQUEST_URI']; ?>">
    <br>
    <input name="DeletePost" type="submit" id="DeletePost" value="Delete Message"><br><br>
    
    <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $HTTP_GET_VARS['ip'];?>">
    <br><br>
    
    <input name="Unban" type="submit" id="Unban" value="Unban <? echo $HTTP_GET_VARS['ip'];?>">
    
        </form>
    <br><br>
    <a href="page.php">Back</a>
    </html>
    
    
  8.  

    Easiest way to batch them is to use array_chunk();

    $f_pointer=fopen("unique.csv","r"); // file pointer
    $users = array();
    while ($ar=fgetcsv($f_pointer)) {
        if (trim($ar[0])!='') $users[] = $ar[0];
    }
    fclose ($f_pointer);
    
    $batchSize = 50;                          // set size of your batches
    
    $batches = array_chunk($users, $batchSize);
    
    foreach ($batches as $batch) {
        $list = join(',', $batch);
        // process the batch list here
    }
    
    

    Ok but when I submit it, only the first 50 people gets the message is it possible to make it loop in batches of 50 till everyone on the list got the message?

  9.  

    Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.

     

    My Http link look something like 

     

    and my ban.php page where I want to lookup the 159 part and do the banning etc looks like

    <?
    include("admin_code_header.php");
    
    
    if ($_POST["DeletePost"]) {
        $id = $_POST['id'];
        $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
        mysql_query($query);
        echo "ID removed from system: ".$id;
      }
    
    
    if ($_POST["BanIP"]) {
        $IP_To_Add = $_POST["ip"];
        
          $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
          $result = mysql_query($sql);
      }
    $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db);
    
      while ($myrow = mysql_fetch_array($result)) {
        $msg = $myrow["StringyChat_message"];
    $idm = $myrow["id"];
    
    
    
    ?>
    <html>
    <form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    
    <input name="DeletePost" type="submit" id="DeletePost" value="Delete">
    
    <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>">
        </form>
    </html>
    <?
    }
    ?>
    
    

    Ok so I spend some more time with the script and made a few more changes. The options display now but nothing happens when I try to execute them.

    First of all I added the ip to my URL as well

     and made a few changes in my ban.php file like the $_POST changed to $_GET and my form action need to be changed not sure to what.

     

    here is my ban.php file

    <?
    include("admin_code_header.php");
    
    
    if ($_POST["DeletePost"]) {
        $id = $_GET["id"];
        $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
        mysql_query($query);
        echo "ID removed from system: ".$id;
      }
    
    
    if ($_POST["BanIP"]) {
        $IP_To_Add = $_GET["ip"];
        
          $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
          $result = mysql_query($sql);
      }
    
    
    
    ?>
    <html>
    <form name="form" method="post" action="ban.php">
    
    <input name="DeletePost" type="submit" id="DeletePost" value="Delete">
    
    <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $_GET['ip'];?>">
        </form>
    </html>
    
    
  10. Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.

     

    My Http link look something like 

     

    and my ban.php page where I want to lookup the 159 part and do the banning etc looks like

    <?
    include("admin_code_header.php");
    
    
    if ($_POST["DeletePost"]) {
        $id = $_POST['id'];
        $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
        mysql_query($query);
        echo "ID removed from system: ".$id;
      }
    
    
    if ($_POST["BanIP"]) {
        $IP_To_Add = $_POST["ip"];
        
          $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
          $result = mysql_query($sql);
      }
    $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db);
    
      while ($myrow = mysql_fetch_array($result)) {
        $msg = $myrow["StringyChat_message"];
    $idm = $myrow["id"];
    
    
    
    ?>
    <html>
    <form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    
    <input name="DeletePost" type="submit" id="DeletePost" value="Delete">
    
    <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>">
        </form>
    </html>
    <?
    }
    ?>
    
    
  11. Hi, I had a chat script lying around but wanted to add a login form in case the mxitid wasn't found in the database so I made a few changes to the script to check for records in databases and retrieving the username according the mxit ID. but after I made few changes im getting syntax errors can someone maybe tell me where I made mistakes please.

    <?php
    // database connection info
    $conn = mysql_connect('*******','********','*******') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('************',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    $query0 = mysql_query("SELECT username FROM Users WHERE mxitid=$mid", $con);
    $result = mysql_query($query0);
                    $myrows = mysql_fetch_array($result);
      if (mysql_num_rows($query0) != 0)
      {
          echo "define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    echo "<html><br>
    <span style="color:red"><b><u>Chat Beta: Errors may apply please send feedback with contact us regarding problems!</u></b></span>
    </html>";
    
    
    
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM StringyChat";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 20;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    
    
    
        /*
         * StringyChat
         *
    	 * Please refer to readme.txt supplied with the StringyChat distribution for information on
    	 * installing and configuring. 
    	 *
         */
    
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    
        include("chat_code_header.php");
    
        $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); 
        $myrow = mysql_fetch_array($result); 
    
        $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on
    	$install_url = $myrow["install_url"]; // URL to install dir of StringyChat
        $name_size = $myrow["name_size"]; // Maximum size of the name
        $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit.
        $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split.
        $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display.
        $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes
    	$email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to
    
        
    	if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) 
        { 
        $StringyChat_name = $_POST['StringyChat_name'];
        $StringyChat_message = $_POST['StringyChat_message'];
        }
    	
    
    
    <div id="StringyChat">
    
    
        // Check if visitor's IP is banned.  If so, do not display the form,
        // show a banned IP message instead.
    
    $name = $myrows["Username"];
    if(!isset($name))
    {
    	$name = "SYSOP";
    }
    
    
    
    
        $ip = $_SERVER["REMOTE_ADDR"];
        $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\"";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        if($myrow["ip"] == "") {	// Checks if IP not found in banned list
    
    
    
    
    ?>
    <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>">
          <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20">
          <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea>
          <br>
          <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message">
        </form>
    </html>
    
    <?
    
        } else {
          echo "Posting disabled - Your IP has been banned.";
        }
        
        // Should we try to create a post?
        if (isset($StringyChat_name) && isset($StringyChat_message)) {
    
            // Remove whitespaces and slashes.
            $name = trim(stripslashes($StringyChat_name));
            $message = trim(stripslashes($StringyChat_message));
    
            
                // Check name and message have been entered.
                if (strlen($name) > 0 && strlen($message) > 0) {
                    
                    // Limit the size of the fields as per variable defnitions.
                    if (strlen($name) > $name_size) {
                        $name = substr($name, 0, $name_size);
                    }
                    if (strlen($message) > $message_size) {
                        $message = substr($message, 0, $message_size);
                    }
                    
                    // Remove new lines from name.
                    $name = str_replace("\n", " ", $name);
                    
    				// Stripping out \r's so email formattnig appears correctly.
    				$message = str_replace("\r", "", $message);
    				
    				// Create an email-friendly version of the message.
    				$message_emailable = str_replace("<br>", "\n", $message);
    				$result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
                    while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	              $the_word = $myrow_wordswap["word"];
                      $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable);
                    }
    
                    // Replace the new lines with encoded line breaks for HTML (thanks milahu).
                    $message = str_replace("\n", "c#lb", $message);
    
                    // Use HTML encoding on ame and message so database doesn't misinterpret data.
    	            $name = htmlentities($name);
                    $message = htmlentities($message, ENT_COMPAT);
    				
                    
                    
                    // IP address of submitter and time of post.
    $ip = $_SERVER["REMOTE_ADDR"];
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"];
    
    
    
    if(!isset($mxitid))
    {
    	$mxitid = "DEFAULT";
    
    }
    if(!isset($name))
    {
    	$name = "SYSOP";
    }
    
    
    
    
                    // check to see if a duplicate exists
                    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 1800 )";
                    $result = mysql_query($sql);
                    $myrow = mysql_fetch_array($result);
    
                    if($myrow["StringyChat_message"] == "") {	// Checks if record not matching in db
                      // Save the record
                      $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)";
                      $result = mysql_query($sql);
    				  
    			
    
                    } else {
                      echo "Duplicate post detected<br>";
                    }                
                }
                else {
                    echo "<font color=\"red\">You must Type a message</font><br><br>";
                }
    
          unset($_POST["StringyChat_name"]);
          unset($_POST["StringyChat_message"]);
          unset($StringyChat_ip);
          unset($StringyChat_name);
          unset($StringyChat_message);
          unset($StringyChat_time);
          unset($mxit_id);
    
        }
        
    // get the info from the db 
    $sql = "SELECT StringyChat_time, StringyChat_name, StringyChat_message FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    function filterBadWords($str)
    {
    	
    	
        $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); 
        $replacements = ":-x";
        
        while($row = mysql_fetch_assoc($result1))
        {
              $str = eregi_replace($row['word'], str_repeat(':-x', strlen($row['word'])), $str);
        }  
        
        return $str;
    }
    
    
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) 
    //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
     {
       // echo data
       //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
    $admin = array('SYSOP','cobusbo');
    
    
    
    if (in_array($list['StringyChat_name'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:red">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />' . '<p>';
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />' . '<p>';
    }
    
    
    
    
    
    
    }
    
    
    
    
    
    
        // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
        $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db);
    
        include("sort_widths.php");
    
        while ($myrow = mysql_fetch_array($result)) {
          $msg = $myrow["StringyChat_message"];
    	  
    	  // Convert the encoded line break into an actual <br> tag (thanks milahu)
          $msg = str_replace("c#lb", "<br>", $msg);
    
          // Convert the encoded image tag into a html tag
          $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg);
    	  
    	  // split the lines
          $msg = htmlwrap($msg, $line_length);
    
          $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
          while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	    $the_word = $myrow_wordswap["word"];
            $msg = ereg_replace($the_word, ":-x",$msg);
          }
    
       
        }
       ?>     
    <?
    
    
    
    
    
    
    
    
    
    // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    
    ?><br>
        <html>  <i>Type your Message here...</i>:<br></html>
    ";
      }
    
      else
      {
        <html>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
    Username:<br>
    <input type="text" name="username" ><br>
    <input type="hidden" value="<?php echo $_SERVER['HTTP_X_MXIT_LOGIN']; ?>" name"userid" >
    
    <br><br>
    <input type="submit" value="Submit">
    </form>
    </html>
    
    <?
    $usernames = $_GET['username'];
    $mid = $_GET['userid'];
    
    $sql0 = "INSERT INTO Users (username,mxitid) VALUES (\"$usernames\",\"$mid\")";
                      $result = mysql_query($sql0);
    
    
    ?>
      }
    
  12.  

    Store in array then join().

    $f_pointer=fopen("unique.csv","r"); // file pointer
    $users = array();
    while ($ar=fgetcsv($f_pointer)) {
        $users[] = $ar[0];
    }
    fclose ($f_pointer);
    
    $list = join(',', $users);
    

    Thank you, I just have another question regarding empty lines will it just ignore the line and move on to the next one or will it just stop where there is an empty line is in between?

    Since the API can send only 500 messages each time is it maybe possible to turn it into batches? and will it work if I point to the unique.csv file stored on another host?

  13. I don't know if I'm missing something obvious here, but can't you just build an array from the initial while loop and then use foreach to loop through each of the id's sending the message to each? Or am I missing something?

     you see the main problem is I need the

     

     

    27823116700

    m59317461002
    27731503630
    m61319393002
    m36816579002
    m38980833002
    m12916668002
    27712673085
    m70046810004
    m8095498002
    m40363282002
    m68756447002
    m6865628002
    m9087505002
    m68741582002
    m47489157002

     

    stored as 

     

     

    27823116700,m59317461002,27731503630,m61319393002,m36816579002,m38980833002,m12916668002,27712673085,m70046810004,m8095498002,m40363282002,m68756447002,m6865628002,m9087505002,m68741582002,m47489157002

  14. Hi Ive currently developed a script that connects via an API to send a message, and tested it with one user and it works perfectly. But now im bit stuck to send it to multiple users. All my visitors unique IDs are being stored into a file called unique.csv all in 1 column under each other. But what im currently trying to do is to recall the info from the csv and make a contact list to broadcast the message to.

     

    The csv file looks like:

     

     

    27823116700

    m59317461002
    27731503630
    m61319393002
    m36816579002
    m38980833002
    m12916668002
    27712673085
    m70046810004
    m8095498002
    m40363282002
    m68756447002
    m6865628002
    m9087505002
    m68741582002
    m47489157002

     

     

    Here is my current script

    <?php
    
    $f_pointer=fopen("unique.csv","r"); // file pointer
    
    while(! feof($f_pointer)){
    $ar=fgetcsv($f_pointer);
    }
    
    
    
    require_once ('MxitAPI.php');
    /* Instantiate the Mxit API */
    $key = '****';
    $secret = '*****';
    $visitor = '****';
    $api = new MxitAPI($key, $secret);
    $api->get_app_token('message/send');
    $api->send_message('guniverse', '$ar[0]', '*test message*', 'true');
    echo 'Success';
    ?>
  15. Hi I'm using php file to retrieve the amount of records in my database, but all of a sudden I get 0 results. It worked fine a few days ago. I got PHP 5.2.* on my host. Here is the current script that I use.

    Did I made a mistake somewhere?

    <?php
    $con=mysqli_connect("******","*****","*****","****");
    
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    $sql="SELECT * FROM mxit";
    
    if ($result=mysqli_query($con,$sql))
      {
     
    
    $rowcount=mysqli_num_rows($result);
      //printf("Result set has %d rows.\n",$rowcount);
    
        
      // Free result set
      mysqli_free_result($result);
    }
    
    mysqli_close($con);
    ?>
    
  16. Hi I'm currently investigating how much it will cost me approximately for someone to code  me a basic chat script.

     

    • The script should be very basic (old school) PHP without any javascript or fancy options. must use Mysql as database.
    • Must use automatic login if the user match to certain HTTP header otherwise they must specify a username to register
    • Should not use css stylesheets must be inline styles
    • No cookies

     

    Moderating

    • time ban(kick) for 1h, 12h, 24h, 7days,  1 month and 1 year and Permanent
    • Option to unkick/ban
    • Option to edit messages and delete messages.
    • The moderator should be able to type under hes real username and by using a prefix like a ? infront of hes message it must be able to post a message under the name Moderator in a different color.
    • Each time a person has been banned a message should appear saying something like user1 has been kicked for 7 days.
    • Display the amount of times being kicked within the last 30 days...

     

     

    Admin Panel

    • time ban(kick) for 1h, 12h, 24h, 7days,  1 month and 1 year and Permanent
    • Option to unkick/ban
    • Option to edit messages and delete messages.
    • The Admin should be able to type under hes real username and by using a prefix like a ! infront of hes message it must be able to post a message under the name Admin in a different color.
    • Each time a person has been banned a message should appear saying something like user1 has been kicked for 7 days.
    • Display the amount of times being kicked within the last 30 days...
    • Option to rename Users usernames
    • Word filter with an option to specify the replacement word
    • Auto mute for specific time frame if a user used a word on the word filter
    • Option to make users moderators and remove them and option to specify text colors of the moderator and Admin and normal user using span and div styles
    • Option to remove messages older then a specified time.
    • Should be able to select how many messages must be displayed per page

     

    Chat window

    • Should show the time posted in brackets in grey, name: and message
    • Should make use of pagination
    • should have a text link to page to show users currently active and chatting
    • Refresh option and highlight the font of the usernames  in another color for new messages appearing after each refresh.
    • If a user is a moderator/admin he should get [x] option next to each message he can select to be able to do all the moderation / admin options of regarding the specific message/user.
    • The Admin should have another admin page regarding the setup of the chat like user/ moderation/admin text colors etc... witch he can access via a link to the specific page.

     

    Note:

    This is just for interest sake no real job offering yet. 

     

    I want this script to be able to be implemented via a .mobi portal on a IM application for mobiles named Mxit. It has many limitations...

  17. Your query is failing and, more importantly, is not secure - you are open to SQL injection. You need to change to mysqli_ or PDO for your DB transactions and use Prepared Statements. That will fix your issue and resolve the SQL Injection problem.

     

    I prefer PDO. here is a cursory tutorial that will get you going in the right direction: http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059

    This will mean I will have to change the script from scratch...

    Isn't there a way to fix it otherwise since its a very old script running on an old version of php 5.4.2 I think...

  18. Hi I'm currently having a problem with my chat script each time I'm trying to insert " or brackets etc... I get the error

     

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/u471530368/public_html/chat/page.php on line 201

     

     

    Here is the lines at line 201

    
    // check to see if a duplicate exists
    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 30 )";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
    
    if($myrow["StringyChat_message"] == "") {    // Checks if record not matching in db
    // Save the record
    $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)";
    $result = mysql_query($sql);
                    
                     $theTo = $email_notification_to;
                     $theSubject = "New StringyChat post at ".$domain_installed;
                     $theMessage = "A new StringyChat post has been made.\n\n";
                     $theMessage .= $name . "\n";
                     $theMessage .= date("H:i - d/m/y", $post_time) . "\n";
                     $theMessage .= $message_emailable . "\n\n";
                     $theMessage .= "Visit ".$domain_installed." to view StringyChat and much more!";
                     $theHeaders = "From: StringyChat at ".$domain_installed." <".$email_notification_to.">\r\n";
                    
                     mail($theTo,$theSubject,$theMessage,$theHeaders);
    
    } else {
    echo "<span style='color:#10ce59'>Duplicate post detected!</span><p>";
    }
    }
    else {
    echo "<span style='color:#10ce59'>You can't send blanks!</span><br><br>";
    }
    

    My full script is

     

    <?php
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    ?>
    <html><br>
    <b><u>Chat Beta:</u></b> 
    <span style="color:#ff0000"><br>Errors may apply please send feedback with contact us regarding problems!</span>
    <br><a href="page.php">Reload</a>
    </html>
    <?
    // database connection info
    $conn = mysql_connect('*******','********','*****') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('*******',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM StringyChat";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    
    // number of rows to show per page
    $rowsperpage = 20;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    
    
    
    
    
    
    
        /*
         * StringyChat
         *
    * Please refer to readme.txt supplied with the StringyChat distribution for information on
    * installing and configuring. 
    *
         */
    
    
    
    
    
    
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    
    
    
    
        include("chat_code_header.php");
    
    
        $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); 
        $myrow = mysql_fetch_array($result); 
    
    
        $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on
    $install_url = $myrow["install_url"]; // URL to install dir of StringyChat
        $name_size = $myrow["name_size"]; // Maximum size of the name
        $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit.
        $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split.
        $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display.
        $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes
    $email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to
    
    
        
    if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) 
        { 
        $StringyChat_name = $_POST['StringyChat_name'];
        $StringyChat_message = $_POST['StringyChat_message'];
        }
    
    
    ?>
    
    
    <div id="StringyChat">
    
    
    <?
        // Check if visitor's IP is banned.  If so, do not display the form,
        // show a banned IP message instead.
    
    
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    if(!isset($name))
    {
    $name = "SYSOP";
    }
    
    
    
    
    
    
    
    
        $ip = $_SERVER["REMOTE_ADDR"];
        $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\"";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        if($myrow["ip"] == "") { // Checks if IP not found in banned list
    
    
    
    
    
    
    
    
    ?>
    <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>">
          <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20">
          <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea>
          <br>
          <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message">
        </form>
    </html>
    
    
    <?
    
    
        } else {
          echo "<span style='color:#10ce59'><u>Dear User, you have been banned from the Chat due to not following the rules. You will need to come back regularly to see if you were unbanned. Until then, goodbye!</u></span>";
        }
        
        // Should we try to create a post?
        if (isset($StringyChat_name) && isset($StringyChat_message)) {
    
    
            // Remove whitespaces and slashes.
            $name = trim(stripslashes($StringyChat_name));
            $message = trim(stripslashes($StringyChat_message));
    
    
            
                // Check name and message have been entered.
                if (strlen($name) > 0 && strlen($message) > 0) {
                    
                    // Limit the size of the fields as per variable defnitions.
                    if (strlen($name) > $name_size) {
                        $name = substr($name, 0, $name_size);
                    }
                    if (strlen($message) > $message_size) {
                        $message = substr($message, 0, $message_size);
                    }
                    
                    // Remove new lines from name.
                    $name = str_replace("\n", " ", $name);
                    
    // Stripping out \r's so email formattnig appears correctly.
    $message = str_replace("\r", "", $message);
    
    
    // Create an email-friendly version of the message.
    $message_emailable = str_replace("<br>", "\n", $message);
    $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
                    while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
                 $the_word = $myrow_wordswap["word"];
                      $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable);
                    }
    
    
                    // Replace the new lines with encoded line breaks for HTML (thanks milahu).
                    $message = str_replace("\n", "c#lb", $message);
    
    
                    // Use HTML encoding on ame and message so database doesn't misinterpret data.
               $name = htmlentities($name);
                    $message = htmlentities($message, ENT_COMPAT);
    
    
                    
                    
                    // IP address of submitter and time of post.
    $ip = $_SERVER["REMOTE_ADDR"];
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"];
    
    
    
    
    
    
    if(!isset($mxitid))
    {
    $mxitid = "DEFAULT";
    
    
    }
    if(!isset($name))
    {
    $name = "SYSOP";
    }
    
    
    
    
    
    
    
    
                    // check to see if a duplicate exists
                    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 30 )";
                    $result = mysql_query($sql);
                    $myrow = mysql_fetch_array($result);
    
    
                    if($myrow["StringyChat_message"] == "") { // Checks if record not matching in db
                      // Save the record
                      $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)";
                      $result = mysql_query($sql);
    
    
     $theTo = $email_notification_to;
     $theSubject = "New StringyChat post at ".$domain_installed;
     $theMessage = "A new StringyChat post has been made.\n\n";
     $theMessage .= $name . "\n";
     $theMessage .= date("H:i - d/m/y", $post_time) . "\n";
     $theMessage .= $message_emailable . "\n\n";
       $theMessage .= "Visit ".$domain_installed." to view StringyChat and much more!";
     $theHeaders = "From: StringyChat at ".$domain_installed." <".$email_notification_to.">\r\n";
    
    
     mail($theTo,$theSubject,$theMessage,$theHeaders);
    
    
                    } else {
                      echo "<span style='color:#10ce59'>Duplicate post detected!</span><p>";
                    }                
                }
                else {
                    echo "<span style='color:#10ce59'>You can't send blanks!</span><br><br>";
                }
    
    
          unset($_POST["StringyChat_name"]);
          unset($_POST["StringyChat_message"]);
          unset($StringyChat_ip);
          unset($StringyChat_name);
          unset($StringyChat_message);
          unset($StringyChat_time);
          unset($mxit_id);
    
    
        }
        
    // get the info from the db 
    $sql = "SELECT StringyChat_time, StringyChat_name, StringyChat_message FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    
    
    
    function filterBadWords($str)
    {
    
    
    
    
        $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); 
        $replacements = ":-x";
        
        while($row = mysql_fetch_assoc($result1))
        {
              $str = eregi_replace($row['word'], str_repeat(':-x', strlen($row['word'])), $str);
        }  
        
        return $str;
    }
    
    
    
    
    
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) 
    //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
     {
       // echo data
       //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
    $admin = array('cobusbo','Admin+TT');
    
    
    
    
    
    
    if (in_array($list['StringyChat_name'], $admin))
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<span style="color:red">' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />' . '<p>';
    }
    else
    {
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' .  '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />' . '<p>';
    }
    
    
    
    
    
    
    
    
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
        // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
        $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db);
    
    
        include("sort_widths.php");
    
    
        while ($myrow = mysql_fetch_array($result)) {
          $msg = $myrow["StringyChat_message"];
    
    
     // Convert the encoded line break into an actual <br> tag (thanks milahu)
          $msg = str_replace("c#lb", "<br>", $msg);
    
    
          // Convert the encoded image tag into a html tag
          $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg);
    
    
     // split the lines
          $msg = htmlwrap($msg, $line_length);
    
    
          $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
          while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
       $the_word = $myrow_wordswap["word"];
            $msg = ereg_replace($the_word, ":-x",$msg);
          }
    
    
       
        }
       ?>     
    <?
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    // end while
    
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    
    
    ?><br>
        <html>  <span style="color:grey"><i>Type Your Message NOW!</i></span>
    <p><a href="page.php">Reload</a> | <a href="http://tt.2fh.co">Home</a><br></html>

    Any help please... If I send normal messages I don't get any errors...

     

  19. The code for in_array is fine the problem is with your code.

     

    $admin is only defined on line 186 if the condition on line 136 is true

     if (isset($StringyChat_name) && isset($StringyChat_message))
    

    You need to modify your code so $admin is not defined within a condition.

    Thank you but that wasn't the problem.

    $admin = array("SYSOP","cobusbo");
    
    

    Wasn't in my query so I had to move it down to just before I did my print out and if function.

    $admin = array("SYSOP","cobusbo");
    
    if (in_array($name, $admin))
    {
        print '<span style="color:red">' . $name . '</span>';
    }
    else
    {
       print $name; 
    } 
  20.  

    Why?

     

    The code you posted in reply #3 is on the right track. The problem is you are giving in_array the wrong values. 

     

    You should pass $name as the first argument and $admin as the second argument.

    if (in_array($name, $admin))
    {
        print '<span style="color:red">' . $name . '</span>';
    }
    else
    {
       print $name; 
    }

    A better way would be to add another column in your users table in the database. The value stored in this column will determine the role the user has. Example normal users have the role set to 1, 2 is for moderators and 3 is for admins.

     

    Then all you need to do is check the role to determine the color of the users name. Example code

    // an array storing the colors for each role. The role is used as the key
    $colors = array(
       1 => 'black',
       2 => 'blue',
       3 => 'red'
    );
    
    $name = 'johnDoe';
    $role = 3;
    
    // dynamically assigns the color based on role
    echo '<span style="color: ' . $colors[$role] . '">' . $name . '</span>'; // will show as red

    Thank you but im stil receiving the same error

     

    Here is my code

    <?php
            /*** begin the session ***/
            session_start();
    
            /*** create the form token ***/
            $form_token = uniqid();
    
            /*** add the form token to the session ***/
            $_SESSION['form_token'] = $form_token;
    
    	require_once('common.php');
    	checkUser();
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    ?>
    <html><br>
    <span style="color:red"><b><u>Chat Beta: Errors may apply please send feedback with contact us regarding problems!</u></b></span>
    </html>
    <?
    // database connection info
    $conn = mysql_connect('*******','******','*****') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('u506124311_cobus',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM StringyChat";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 20;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    
    
    
        /*
         * StringyChat
         *
    	 * Please refer to readme.txt supplied with the StringyChat distribution for information on
    	 * installing and configuring. 
    	 *
         */
    
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    
        include("chat_code_header.php");
    
        $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); 
        $myrow = mysql_fetch_array($result); 
    
        $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on
    	$install_url = $myrow["install_url"]; // URL to install dir of StringyChat
        $name_size = $myrow["name_size"]; // Maximum size of the name
        $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit.
        $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split.
        $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display.
        $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes
    	$email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to
    
        
    	if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) 
        { 
        $StringyChat_name = $_POST['StringyChat_name'];
        $StringyChat_message = $_POST['StringyChat_message'];
        }
    	
    ?>
    
    <div id="StringyChat">
    
    <?
        // Check if visitor's IP is banned.  If so, do not display the form,
        // show a banned IP message instead.
    
    
        $ip = $_SERVER["REMOTE_ADDR"];
        $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\"";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        if($myrow["ip"] == "") {	// Checks if IP not found in banned list
    
    
    
    
    ?>
    <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>">
          <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $_SESSION['userName']; ?>" size="20">
          <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea>
          <br>
          <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message">
        </form>
    </html>
    
    <?
    
        } else {
          echo "Posting disabled - Your IP has been banned.";
        }
        
        // Should we try to create a post?
        if (isset($StringyChat_name) && isset($StringyChat_message)) {
    
            // Remove whitespaces and slashes.
            $name = trim(stripslashes($StringyChat_name));
            $message = trim(stripslashes($StringyChat_message));
    
            
                // Check name and message have been entered.
                if (strlen($name) > 0 && strlen($message) > 0) {
                    
                    // Limit the size of the fields as per variable defnitions.
                    if (strlen($name) > $name_size) {
                        $name = substr($name, 0, $name_size);
                    }
                    if (strlen($message) > $message_size) {
                        $message = substr($message, 0, $message_size);
                    }
                    
                    // Remove new lines from name.
                    $name = str_replace("\n", " ", $name);
                    
    				// Stripping out \r's so email formattnig appears correctly.
    				$message = str_replace("\r", "", $message);
    				
    				// Create an email-friendly version of the message.
    				$message_emailable = str_replace("<br>", "\n", $message);
    				$result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
                    while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	              $the_word = $myrow_wordswap["word"];
                      $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable);
                    }
    
                    // Replace the new lines with encoded line breaks for HTML (thanks milahu).
                    $message = str_replace("\n", "c#lb", $message);
    
                    // Use HTML encoding on ame and message so database doesn't misinterpret data.
    	            $name = htmlentities($name);
                    $message = htmlentities($message, ENT_COMPAT);
    				
                    
                    
                    // IP address of submitter and time of post.
    $ip = $_SERVER["REMOTE_ADDR"];
    $name = $_SESSION['userName'];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $admin = array("SYSOP","cobusbo");
    $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"];
    
    
    
    if(!isset($mxitid))
    {
    	$mxitid = "DEFAULT";
    
    }
    if(!isset($name))
    {
    	$name = "SYSOP";
    }
    
    
    
    
                    // check to see if a duplicate exists
                    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 1800 )";
                    $result = mysql_query($sql);
                    $myrow = mysql_fetch_array($result);
    
                    if($myrow["StringyChat_message"] == "") {	// Checks if record not matching in db
                      // Save the record
                      $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)";
                      $result = mysql_query($sql);
    				  
    				  $theTo = $email_notification_to;
    				  $theSubject = "New StringyChat post at ".$domain_installed;
    				  $theMessage = "A new StringyChat post has been made.\n\n";
    				  $theMessage .= $name . "\n";
    				  $theMessage .= date("H:i - d/m/y", $post_time) . "\n";
    				  $theMessage .= $message_emailable . "\n\n";
      				  $theMessage .= "Visit ".$domain_installed." to view StringyChat and much more!";
    				  $theHeaders = "From: StringyChat at ".$domain_installed." <".$email_notification_to.">\r\n";
    				  
    				  mail($theTo,$theSubject,$theMessage,$theHeaders);
    
                    } else {
                      echo "Duplicate post detected<br>";
                    }                
                }
                else {
                    echo "<font color=\"red\">You must Type a message</font><br><br>";
                }
    
          unset($_POST["StringyChat_name"]);
          unset($_POST["StringyChat_message"]);
          unset($StringyChat_ip);
          unset($StringyChat_name);
          unset($StringyChat_message);
          unset($StringyChat_time);
          unset($mxit_id);
    
        }
        
    // get the info from the db 
    $sql = "SELECT StringyChat_time, StringyChat_name, StringyChat_message FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    function filterBadWords($str)
    {
    	
    	
        $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); 
        $replacements = ":-x";
        
        while($row = mysql_fetch_assoc($result1))
        {
              $str = eregi_replace($row['word'], str_repeat(':-x', strlen($row['word'])), $str);
        }  
        
        return $str;
    }
    
    
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) 
    //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
     {
       // echo data
       //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
    
    
    
    
    
    
    if (in_array($name, $admin))
    {
        print '<span style="color:red">' . $name . '</span>';
    }
    else
    {
       print $name; 
    }
    
    
    
    
    
    
    
    
    
    
    }
    
    
    
    
    
    
        // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
        $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db);
    
        include("sort_widths.php");
    
        while ($myrow = mysql_fetch_array($result)) {
          $msg = $myrow["StringyChat_message"];
    	  
    	  // Convert the encoded line break into an actual <br> tag (thanks milahu)
          $msg = str_replace("c#lb", "<br>", $msg);
    
          // Convert the encoded image tag into a html tag
          $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg);
    	  
    	  // split the lines
          $msg = htmlwrap($msg, $line_length);
    
          $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
          while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	    $the_word = $myrow_wordswap["word"];
            $msg = ereg_replace($the_word, ":-x",$msg);
          }
    
       
        }
       ?>     
    <?
    
    
    
    
    
    
    
    
    
    // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    
    ?><br>
        <html>  <i>Type your Message here...</i>:<br></html>
    
    <?
    include "menu3.php";
    ?>
    
    

    And the error message is 

     

    Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/u506124311/public_html/ag/page.php on line 269

     

  21. The error message tells you what you did wrong.

     

    If you have read the documentation for in_array you would understand what values it expects.

    Ok I'm going to pass on the arrays I tried to do it with one value only

    if ($name = "cobusbo")
    {
    $name = '<span style="color:red">' . '$name' . '</span>';
    }
    else
    {
    $name = '$name'; 
    }
    
    

    What im basically trying to do is to specify admin users and moderator users. So if their name is cobusbo I want their message to appear in red. But currently the above insertion has no impact what so ever on my chat. all colors stil display in black...

     

    I'm not sure what I should do regarding this problem...

  22. $admin is an array. It doesn't make sense to compare a string to an array.

     

    You want in_array.

    Ok thanks I've implemented it but seems like I have done something wrong

     

    here is my current code

    <?php
            /*** begin the session ***/
            session_start();
    
            /*** create the form token ***/
            $form_token = uniqid();
    
            /*** add the form token to the session ***/
            $_SESSION['form_token'] = $form_token;
    
    	require_once('common.php');
    	checkUser();
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    ?>
    <html><br>
    <span style="color:red"><b><u>Chat Beta: Errors may apply please send feedback with contact us regarding problems!</u></b></span>
    </html>
    <?
    // database connection info
    $conn = mysql_connect('**********','u506124311_***********') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('u506124311_cobus',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM StringyChat";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 20;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    
    
    
        /*
         * StringyChat
         *
    	 * Please refer to readme.txt supplied with the StringyChat distribution for information on
    	 * installing and configuring. 
    	 *
         */
    
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    
        include("chat_code_header.php");
    
        $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); 
        $myrow = mysql_fetch_array($result); 
    
        $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on
    	$install_url = $myrow["install_url"]; // URL to install dir of StringyChat
        $name_size = $myrow["name_size"]; // Maximum size of the name
        $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit.
        $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split.
        $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display.
        $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes
    	$email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to
    
        
    	if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) 
        { 
        $StringyChat_name = $_POST['StringyChat_name'];
        $StringyChat_message = $_POST['StringyChat_message'];
        }
    	
    ?>
    
    <div id="StringyChat">
    
    <?
        // Check if visitor's IP is banned.  If so, do not display the form,
        // show a banned IP message instead.
    
    
        $ip = $_SERVER["REMOTE_ADDR"];
        $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\"";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        if($myrow["ip"] == "") {	// Checks if IP not found in banned list
    
    
    
    
    ?>
    <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>">
          <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $_SESSION['userName']; ?>" size="20">
          <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea>
          <br>
          <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message">
        </form>
    </html>
    
    <?
    
        } else {
          echo "Posting disabled - Your IP has been banned.";
        }
        
        // Should we try to create a post?
        if (isset($StringyChat_name) && isset($StringyChat_message)) {
    
            // Remove whitespaces and slashes.
            $name = trim(stripslashes($StringyChat_name));
            $message = trim(stripslashes($StringyChat_message));
    
            
                // Check name and message have been entered.
                if (strlen($name) > 0 && strlen($message) > 0) {
                    
                    // Limit the size of the fields as per variable defnitions.
                    if (strlen($name) > $name_size) {
                        $name = substr($name, 0, $name_size);
                    }
                    if (strlen($message) > $message_size) {
                        $message = substr($message, 0, $message_size);
                    }
                    
                    // Remove new lines from name.
                    $name = str_replace("\n", " ", $name);
                    
    				// Stripping out \r's so email formattnig appears correctly.
    				$message = str_replace("\r", "", $message);
    				
    				// Create an email-friendly version of the message.
    				$message_emailable = str_replace("<br>", "\n", $message);
    				$result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
                    while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	              $the_word = $myrow_wordswap["word"];
                      $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable);
                    }
    
                    // Replace the new lines with encoded line breaks for HTML (thanks milahu).
                    $message = str_replace("\n", "c#lb", $message);
    
                    // Use HTML encoding on ame and message so database doesn't misinterpret data.
    	            $name = htmlentities($name);
                    $message = htmlentities($message, ENT_COMPAT);
    				
                    
                    
                    // IP address of submitter and time of post.
    $ip = $_SERVER["REMOTE_ADDR"];
    $name = $_SESSION['userName'];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $admin = array("SYSOP","~cobusbo~");
    $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"];
    
    if (in_array("SYSOP", "cobusbo", $admin))
    {
    print '<span style="color:red">' . $name . '</span>';
    }
    else
    {
    print '$name'; 
    }
    
    
    if(!isset($mxitid))
    {
    	$mxitid = "DEFAULT";
    
    }
    if(!isset($name))
    {
    	$name = "SYSOP";
    }
    
    
    
    
                    // check to see if a duplicate exists
                    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 1800 )";
                    $result = mysql_query($sql);
                    $myrow = mysql_fetch_array($result);
    
                    if($myrow["StringyChat_message"] == "") {	// Checks if record not matching in db
                      // Save the record
                      $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)";
                      $result = mysql_query($sql);
    				  
    				  $theTo = $email_notification_to;
    				  $theSubject = "New StringyChat post at ".$domain_installed;
    				  $theMessage = "A new StringyChat post has been made.\n\n";
    				  $theMessage .= $name . "\n";
    				  $theMessage .= date("H:i - d/m/y", $post_time) . "\n";
    				  $theMessage .= $message_emailable . "\n\n";
      				  $theMessage .= "Visit ".$domain_installed." to view StringyChat and much more!";
    				  $theHeaders = "From: StringyChat at ".$domain_installed." <".$email_notification_to.">\r\n";
    				  
    				  mail($theTo,$theSubject,$theMessage,$theHeaders);
    
                    } else {
                      echo "Duplicate post detected<br>";
                    }                
                }
                else {
                    echo "<font color=\"red\">You must Type a message</font><br><br>";
                }
    
          unset($_POST["StringyChat_name"]);
          unset($_POST["StringyChat_message"]);
          unset($StringyChat_ip);
          unset($StringyChat_name);
          unset($StringyChat_message);
          unset($StringyChat_time);
          unset($mxit_id);
    
        }
        
    // get the info from the db 
    $sql = "SELECT StringyChat_time, StringyChat_name, StringyChat_message FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    function filterBadWords($str)
    {
    	
    	
        $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); 
        $replacements = ":-x";
        
        while($row = mysql_fetch_assoc($result1))
        {
              $str = eregi_replace($row['word'], str_repeat(':-x', strlen($row['word'])), $str);
        }  
        
        return $str;
    }
    
    
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) 
    //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
     {
       // echo data
       //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
    
    
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />' . '<p>';
    
    
    }
    
    
    
    
    
    
        // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
        $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db);
    
        include("sort_widths.php");
    
        while ($myrow = mysql_fetch_array($result)) {
          $msg = $myrow["StringyChat_message"];
    	  
    	  // Convert the encoded line break into an actual <br> tag (thanks milahu)
          $msg = str_replace("c#lb", "<br>", $msg);
    
          // Convert the encoded image tag into a html tag
          $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg);
    	  
    	  // split the lines
          $msg = htmlwrap($msg, $line_length);
    
          $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
          while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	    $the_word = $myrow_wordswap["word"];
            $msg = ereg_replace($the_word, ":-x",$msg);
          }
    
       
        }
       ?>     
    <?
    
    
    
    
    
    
    
    
    
    // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    
    ?><br>
        <html>  <i>Type your Message here...</i>:<br></html>
    
    <?
    include "menu3.php";
    ?>
    
    

    Seems like I did something wrong over here

                  // IP address of submitter and time of post.
    $ip = $_SERVER["REMOTE_ADDR"];
    $name = $_SESSION['userName'];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $admin = array("SYSOP","~cobusbo~");
    $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"];
    
    if (in_array("SYSOP", "cobusbo", $admin))
    {
    print '<span style="color:red">' . $name . '</span>';
    }
    else
    {
    print '$name'; 
    }
    

    Im getting the following error each time Im trying to post a message

     

     

     

    Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/u506124311/public_html/ag/page.php on line 185

  23. Hi I'm trying to make use of an array with usernames in it and want to make use of it to display users with those usernames in a certain color in this case Im trying red.

     

    I've made an array with username in it

    $admin = array("SYSOP","~cobusbo~");
    
    

    and I've tried to  print these messages with color with the If function without luck

    if ($name == $admin) {
    $name = print '<span style="color:red">' . $_SERVER["HTTP_X_MXIT_NICK"] . '</span>';
    }
    else
    {
    $name = print $_SERVER["HTTP_X_MXIT_NICK"];
    }
    
    

    Here is my full code

    <?php
            /*** begin the session ***/
            session_start();
    
            /*** create the form token ***/
            $form_token = uniqid();
    
            /*** add the form token to the session ***/
            $_SESSION['form_token'] = $form_token;
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
    
    
    // database connection info
    $conn = mysql_connect('**********','********','**********') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('u506124311_cobus',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    // find out how many rows are in the table 
    $sql = "SELECT COUNT(*) FROM StringyChat";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 20;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    
    
    
        /*
         * StringyChat
         *
    	 * Please refer to readme.txt supplied with the StringyChat distribution for information on
    	 * installing and configuring. 
    	 *
         */
    
    
    
    
    
    
    
    
    define('TIMEZONE', 'Africa/Harare');
    date_default_timezone_set(TIMEZONE);
    
        include("chat_code_header.php");
    
        $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); 
        $myrow = mysql_fetch_array($result); 
    
        $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on
    	$install_url = $myrow["install_url"]; // URL to install dir of StringyChat
        $name_size = $myrow["name_size"]; // Maximum size of the name
        $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit.
        $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split.
        $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display.
        $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes
    	$email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to
    
        
    	if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) 
        { 
        $StringyChat_name = $_POST['StringyChat_name'];
        $StringyChat_message = $_POST['StringyChat_message'];
        }
    	
    ?>
    
    <div id="StringyChat">
    
    <?
        // Check if visitor's IP is banned.  If so, do not display the form,
        // show a banned IP message instead.
    
    
        $ip = $_SERVER["REMOTE_ADDR"];
        $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\"";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        if($myrow["ip"] == "") {	// Checks if IP not found in banned list
    
    
    
    
    ?>
    <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>">
          <br>
          <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php $name ?>1" size="20">
          <br>
          <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="4"></textarea>
          <br>
          <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message">
        </form>
    </html>
    
    <?
    
        } else {
          echo "Posting disabled - Your IP has been banned.";
        }
        
        // Should we try to create a post?
        if (isset($StringyChat_name) && isset($StringyChat_message)) {
    
            // Remove whitespaces and slashes.
            $name = trim(stripslashes($StringyChat_name));
            $message = trim(stripslashes($StringyChat_message));
    
            
                // Check name and message have been entered.
                if (strlen($name) > 0 && strlen($message) > 0) {
                    
                    // Limit the size of the fields as per variable defnitions.
                    if (strlen($name) > $name_size) {
                        $name = substr($name, 0, $name_size);
                    }
                    if (strlen($message) > $message_size) {
                        $message = substr($message, 0, $message_size);
                    }
                    
                    // Remove new lines from name.
                    $name = str_replace("\n", " ", $name);
                    
    				// Stripping out \r's so email formattnig appears correctly.
    				$message = str_replace("\r", "", $message);
    				
    				// Create an email-friendly version of the message.
    				$message_emailable = str_replace("<br>", "\n", $message);
    				$result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
                    while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	              $the_word = $myrow_wordswap["word"];
                      $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable);
                    }
    
                    // Replace the new lines with encoded line breaks for HTML (thanks milahu).
                    $message = str_replace("\n", "c#lb", $message);
    
                    // Use HTML encoding on ame and message so database doesn't misinterpret data.
    	            $name = htmlentities($name);
                    $message = htmlentities($message, ENT_COMPAT);
    				
                    
                    
                    // IP address of submitter and time of post.
    $ip = $_SERVER["REMOTE_ADDR"];
    $name = $_SERVER["HTTP_X_MXIT_NICK"];
    $msg = $_POST['StringyChat_message'];
    $post_time = date("U");
    $admin = array("SYSOP","~cobusbo~");
    $mxitid = $_SERVER["HTTP_X_MXIT_USERID_R"];
    
    
    
    if ($name == $admin) {
    $name = print '<span style="color:red">' . $_SERVER["HTTP_X_MXIT_NICK"] . '</span>';
    }
    else
    {
    $name = print $_SERVER["HTTP_X_MXIT_NICK"];
    }
    
    if(!isset($mxitid, $name ))
    {
    	$mxitid = "DEFAULT";
    	$name = "SYSOP";
    
    }
    
                    // check to see if a duplicate exists
                    $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 3600 )";
                    $result = mysql_query($sql);
                    $myrow = mysql_fetch_array($result);
    
                    if($myrow["StringyChat_message"] == "") {	// Checks if record not matching in db
                      // Save the record
                      $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time,mxit_id) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time,$mxitid)";
                      $result = mysql_query($sql);
    				  
    				  $theTo = $email_notification_to;
    				  $theSubject = "New StringyChat post at ".$domain_installed;
    				  $theMessage = "A new StringyChat post has been made.\n\n";
    				  $theMessage .= $name . "\n";
    				  $theMessage .= date("H:i - d/m/y", $post_time) . "\n";
    				  $theMessage .= $message_emailable . "\n\n";
      				  $theMessage .= "Visit ".$domain_installed." to view StringyChat and much more!";
    				  $theHeaders = "From: StringyChat at ".$domain_installed." <".$email_notification_to.">\r\n";
    				  
    				  mail($theTo,$theSubject,$theMessage,$theHeaders);
    
                    } else {
                      echo "Duplicate post detected<br>";
                    }                
                }
                else {
                    echo "<font color=\"red\">You must Type a message</font><br><br>";
                }
    
          unset($_POST["StringyChat_name"]);
          unset($_POST["StringyChat_message"]);
          unset($StringyChat_ip);
          unset($StringyChat_name);
          unset($StringyChat_message);
          unset($StringyChat_time);
        }
        
    // get the info from the db 
    $sql = "SELECT StringyChat_time, StringyChat_name, StringyChat_message FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    
    
    function filterBadWords($str)
    {
    	
    	
        $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); 
        $replacements = ":-x";
        
        while($row = mysql_fetch_assoc($result1))
        {
              $str = eregi_replace($row['word'], str_repeat(':-x', strlen($row['word'])), $str);
        }  
        
        return $str;
    }
    
    
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) 
    //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
     {
       // echo data
       //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message'])
    
    
       print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] )  . ') ' . '</span>' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />';
    
    
    }
    
    
    
    
    
    
        // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
        $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db);
    
        include("sort_widths.php");
    
        while ($myrow = mysql_fetch_array($result)) {
          $msg = $myrow["StringyChat_message"];
    	  
    	  // Convert the encoded line break into an actual <br> tag (thanks milahu)
          $msg = str_replace("c#lb", "<br>", $msg);
    
          // Convert the encoded image tag into a html tag
          $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg);
    	  
    	  // split the lines
          $msg = htmlwrap($msg, $line_length);
    
          $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db);
          while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) {
    	    $the_word = $myrow_wordswap["word"];
            $msg = ereg_replace($the_word, ":-x",$msg);
          }
    
       
        }
       ?>     
    <?
    
    
    
    
    
    
    
    
    
    // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
    
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    ?><br>
        <html>  <i>Type your Message here...</i>:<br></html>
    
    
×
×
  • 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.