Hi, I have this code here:


include 'core/init.php';
include 'includes/overall/overall_header.php'; 
<h1>Welcome to AwsomeChat!</h1>
<p>This is AwsomeChat - a free place just to hang out. This site is made for chatting or socializing with a friend. This site is free, no membership needed to use this site.</p>
if(logged_in() === true) {
    <script type="text/javascript">
    $(document).ready(function() {

    $("#chat").submit(function() {

        $.post('chat/ajaxPost.php', $('#chat').serialize(), function(data) {
        return false;
    setInterval(function () {
    }, 1000);

    <h3>Welcome, <?php echo $user_data['username']; ?>!</h3>

    <!--Messages form-->
    <form id="chat">

        <input type="text" maxlength="200" name="messages" id="message" placeholder="Type your message here." /><br>
        <input type="submit" value="Send" />


    <!--Display the messages here-->
    <div id="messages"></div>

include 'includes/overall/overall_footer.php'; 


include 'config.php';
include '../core/init.php';

mysql_connect('localhost', 'root', '');

$v = trim($_POST['messages']);
if(logged_in() === false){
    // Redirect to the index.php page
    header('Location: http://www.url.tk/test/');
} else if(empty($v)){

} else {
    $message = mysql_real_escape_string(htmlentities($_POST['messages']));
    $username = $user_data['username'];
    $DB->Query("INSERT INTO messages(`username`, `message`, `time`) VALUES('$username', '$message', UNIX_TIMESTAMP())");
echo $message;


include 'config.php';
include '../core/init.php';
$DB->Query('SELECT * FROM `messages` ORDER BY  `messages`.`id` DESC LIMIT 0, 10');
$data = $DB->Get();
foreach($data as $key => $value) {
    $profile_image = user_profile_from_username($value['username']);
    $postid = $value['id'];
    $username = $value['username'];
    $status = user_online($username);
    $text = autolink($value['message']);
    // Is the user online?
    if ($status === false){
        //The user is offline
        $online = "Offline";
        $style = "color:red;";
    } else {
        //The user is online
        $online = "Online";
        $style = "color:green;";
    echo "<table style='background-color:lightblue; border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; '>" . "<tr>" . "<td>" . "<a href='$value[username]'><img src='$profile_image' width='120' height='120' /></a>" . "</td>" . "<td>" . "<a href='$value[username]'>$value[username]</a> &nbsp; &nbsp; <b style='$style'>$online</b>" . "<br /><br />" . "<div style='width:400px; word-wrap:break-word; overflow:auto;'><b>" . $text . "</b>" . "</div>" . "<br />" . "<a href='http://www.url.tk/report.php?ref=chat_message&username=$username'>Report</a>" . "&nbsp;&nbsp;&nbsp;" . "<a href='http://www.url.tk/test/chat/delete.php?id=" . $value['id'] . "'>Delete Post</a>" . "</td>" . "</tr>" . "</table>" . "<br />";

This code works, I just need to know where to put a wait function so that the user cannot post more than one post per 2 seconds.


Member Avatar

How about disabling the button? Here's some jQuery I cobbled together:

$(function() {
        $('#mybutton').attr("disabled", "disabled");
        setTimeout(enableMe, 2000);

    function enableMe(){

That just goes in your <script> tag

I don't think it would stop a guy with multiple tabs of your chat though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.