I have created a chat window using php, ajax, and jquery. It successfully reads and writes to a file called chatlog.html. I have made a button that clears the chat. It works fine, but all of the clients' chats don't clear until someone speaks. How would I fix this?
chat.php is here since I can't format it correctly: http://pastebin.com/AEwjeZ3w
sendchatmsg.php:
<?php
session_start();
if (isset($_SESSION['username'])) {
$text = $_POST['cmsg'];
$fp = fopen("chatlog.html", "a");
fwrite($fp, "<div><b>" . $_SESSION['username'] . "</b>: " . stripslashes(htmlspecialchars($text)) . "<br></div>");
fclose($fp);
}
?>
clearchat.php:
<?php
unlink("chatlog.html");
?>