[HELP]ChatBox display[HELP]

Status
Not open for further replies.

Li1M0ST3Rz

I <3 Bianca
Sep 13, 2010
269
166
My chatbox is doing strange....
The displaying message doubles..
Ex)
Before;
acss9v.png

After;
21lpzl1.png


Codes:
Comments.php
PHP:
<?php
if(isset($_GET['logout'])){   
   
    //Simple exit message
    $fp = fopen("log.html", 'a'); {
    if($row['userlevel'] ==9);
    fwrite($fp, "<div class='msgln'><i>User <span style='background: url(/admin/images/backround6.gif)'>". $row['username'] ."</span> has left the chat session.</i><br></div>");
}
 
    if($row['userlevel'] == 8); {
    fwrite($fp, "<div class='msgln'><i>User <span style='background: url(/admin/images/backround9.gif)'>". $row['username'] ."</span> has left the chat session.</i><br></div>");
}
 
    if($row['userlevel'] == 1); {
    fwrite($fp, "<div class='msgln'><i>User ". $row['username'] ." has left the chat session.</i><br></div>");
}
    fclose($fp);
   
    session_destroy();
    header("Location: index.php"); //Redirect the user
}
?>
<title><?php echo $core->site_name;?> ~ Comments!</title>
<link rel="stylesheet" type="text/css" href="cb_style.css">
    <div class="box">
        <table border="0" cellpadding="3" cellspacing="0" class="display">
<thead>
      <tr>
    <div id="menu" class="inputbox">
        <p class="welcome"><?php if($user->is_Admin()):?>
  Welcome, <b><span style="background: url(/admin/images/backround6.gif)"><?php echo $row['username']; ?></span> enter. chatbox <a href="./admin.php">Admin Control Panel</a>
<?php endif;?>
<?php if($user->logged_in):?>
  Welcome, <b><?php echo $row['username']; ?>
  <?php endif;?>
  <?php if($row['userlevel'] == 8):?>
  Welcome, <b><span style="background: url(/admin/images/backround9.gif)"><?php echo $row['username']; ?></span> enter. chatbox <a href="./mod.php">Mod Control Panel</a>
    <?php else:?>
  <?php endif;?></b></p>
        <p class="logout"><a id="exit" href="admin.php?logout=true"><center>LogOut</center></a></p>
        <div style="clear:both"></div>
    </div>   
    <div id="chatbox" class="inputbox"><?php
    if(file_exists("log.html") && filesize("log.html") > 0){
        $handle = fopen("log.html", "r");
        $contents = fread($handle, filesize("log.html"));
        fclose($handle);
       
        echo $contents;
    }
    ?></div>
   
    <form name="message" action="">
              <center><textarea  name="usermsg" id="usermsg" class="inputbox" maxlength="1000" cols="29" rows="9"></textarea></center>
        &nbsp;&nbsp;&nbsp;&nbsp;<input name="submitmsg" type="submit" class="button" id="submitmsg" value="Send" />
    </form>
      </tr>
 
</thead>
</td>
            </tr>
          <tr>
        </table>
 
    </div>
    <br />
    </div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
// jQuery Document
$(document).ready(function(){
    //If user submits the form
    $("#submitmsg").click(function(){   
        var clientmsg = $("#usermsg").val();
        $.post("post.php", {text: clientmsg});               
        $("#usermsg").attr("value", "");
        return false;
    });
   
    //Load the file containing the chat log
    function loadLog(){       
        var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
        $.ajax({
            url: "log.html",
            cache: false,
            success: function(html){       
                $("#chatbox").html(html); //Insert chat log into the #chatbox div               
                var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
                if(newscrollHeight > oldscrollHeight){
                    $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
                }               
              },
        });
    }
    setInterval (loadLog, 2500);    //Reload file every 2.5 seconds
   
    //If user wants to end session
    $("#exit").click(function(){
        var exit = confirm("Are you sure you want to end the session?");
        if(exit==true){window.location = 'comments.php?logout=true';}       
    });
});
</script>

Post.php:
PHP:
<?php
session_start();
    $text = $_POST['text'];
   
    $fp = fopen("log.html", 'a');
    if($user->is_Admin()):
    fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b><span style='background: url(/admin/images/backround6.gif)'>". $row['username'] ."</span></b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
    endif;
    fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>". $row['username'] ."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
    fclose($fp);
?>
 

Donkjam

Professional Moderator
Contributor
Nov 20, 2010
1,610
1,605
I'm not too good with PHP but try

Code:
<?php
session_start();
    $text = $_POST['text'];
   
    $fp = fopen("log.html", 'a');
    if($user->is_Admin()):
    fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b><span style='background: url(/admin/images/backround6.gif)'>". $row['username'] ."</span></b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
    Else
    fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>". $row['username'] ."</b>: ".stripslashes(htmlspecialchars($text))."<br>
</div>");
    fclose($fp);
Endif;
?>

Not sure if needs else;
 
Status
Not open for further replies.

Users who are viewing this thread

Top