<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $user = $_POST["user"];
    $message = $_POST["message"];
    if (!empty($user) && !empty($message)) {
        saveMessage($user, $message);
    }
}

function saveMessage($user, $message) {
    $filename = "messages.txt";
    $content = $user . " - " . "<img src='../../img/user.png' style='width: 27px;height: 27px;border-radius: 50%;margin-right: 7px;' />". $message . "<span class='time'>". date("H:i") ."</span>". "\n";
    file_put_contents($filename, $content, FILE_APPEND);
}
?>
