2018-03-02 01:21:53 +02:00
< ? 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 " ;
2018-03-22 21:32:48 +02:00
//include_once "functions.php";
2018-03-02 01:21:53 +02:00
2018-03-24 00:04:55 +02:00
$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 );
2018-03-02 11:29:28 +02:00
2018-03-22 20:32:37 +02:00
function show_messages ()
{
$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> " ;
}
2018-03-02 01:21:53 +02:00
}
2018-03-24 01:08:05 +02:00
show_messages ();
2018-03-02 01:21:53 +02:00
?>
2018-03-24 01:08:05 +02:00
<!--<!doctype html>-->
<!--<html>-->
<!--<head>-->
<!-- <meta charset="utf-8">-->
<!-- <link rel="stylesheet" href="css/main.css">-->
<!-- <style>-->
<!-- form { padding: 3px; position: fixed; bottom: 0; width: 100%; }-->
<!-- form input { border: 0; padding: 10px; width: 80%; margin-right: .5%; }-->
<!-- form input[type="submit"] { width: 15%; border: none; padding: 10px; }-->
<!-- </style>-->
<!--</head>-->
<!--<body>-->
<!--<div>-->
<?php ?>
<!--</div>-->
<!--<!--<form action="chat.php" method="post">-->-->
<!--<!-- <input id="msg" name="msg" size="100" placeholder="Введите сообщение...">-->-->
<!--<!-- <input type="submit" value="Отправить">-->-->
<!--<!--</form>-->-->
<!--</body>-->