battles/chat.php
2018-03-02 23:03:59 +02:00

41 lines
1.1 KiB
PHP

<?php
/**
* Copyright (c) 2018.
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
session_start();
if ($_SESSION['uid'] == null) {
header("Location: index.php");
}
include_once "config.php";
include_once "functions.php";
$msg = filter_input(INPUT_POST,'msg');
$uid = $_SESSION['uid'];
if ($msg) db::c()->query('INSERT INTO `chat` (`cid`, `uid`, `msg`) VALUES (?i, ?i, "?s")', 1, $uid, $msg);
$chat = db::c()->query('SELECT `msg`, `msgdate`, (SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from` FROM `chat` ORDER BY `id` ASC LIMIT 50');
while ($message = $chat->fetch_assoc()) {
$d = new DateTime($message['msgdate']);
$m = htmlspecialchars($message['msg']);
echo sprintf('%s [%s]: %s', $d->format('H:i'),$message['from'],$m)." <br>";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<form action="chat.php" method="post">
<input name="msg" size="100" placeholder="Введите сообщение...">
<input type="submit">
</form>
</body>