I’m folowing this tutorial to create php/jquery based chat application.
In short, this code puts message to log:
<?
session_start();
if(isset($_SESSION['name'])){
$text = $_POST['text'];
$fp = fopen("log.html", 'a');
fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
fclose($fp);
}
?>
And this line of code displays log
function loadLog(){
$.ajax({
url: "log.html",
cache: false,
success: function(html){
$("#chatbox").html(html); //Insert chat log into the #chatbox div
},
});
}
Log is just simple HTML document.
How could I limit log to display only last 100 messages? And that log doesn’t get too big? ( over 1 MB )
The following should be what you want: