So I am making a chatroom, and the way I currently have it set up is that when someone hits the send button, it writes the message to a log file. A separate frame in the same window is set to echo the contents of log.txt via file_get_contents('log.txt')
on a 2 second refresh loop (<meta http-equiv="refresh" content="2"/>
). I could leave it like this, but I don't want to overload the site. I have thought of a better solution and that is to reload the messages window for all connected users whenever someone hits the send button.
Here is the code that controls that button:
<?php
session_start();
echo "<html>";
echo "<head></head> <body>";
echo "<form action='newmessage.php', method='POST'>";
echo "<input type='text' name='message' style='background-color:#202020; color:#FFFFFF;' required minlength='1' maxlength='5000' size='125'/>";
echo "<input type='submit' name='Send' value='Send' style='background-color:#4a4a4a; color:#FFFFFF;'/>";
echo "</form>";
if (ISSET($_POST['message'])) {
$file = "log.txt";
$handle = fopen($file, "a");
fwrite($handle, $_POST['message']);
//
//
//
//
// Insert global page reload code here
//
//
//
//
}
echo "</form>";
echo "</body>";
echo "</html>";
?>
So how would I do this? I am basically a complete php noob, so if I am missing something obvious, please let me know.
Best regards,
Adi