<?php //Limeza do cookie setcookie('nome', '',time()-3600*24); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $nome = trim(filter_input(INPUT_POST, 'nome')); if (empty($nome)) { $erro = 'Nome é Obrigatório'; } else { require "config/config.php"; $chat = new Chat(); $chat->setNome($nome); if ($chat->existeNome()) { $erro = 'Já existe alguém usando esse nome'; } else { setcookie('nome', $chat->getNome(), time() + 3600 * 24 * TEMPO_LIMITE); header('location:chat-index.php'); } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Entrando no Sistema</title> <!--BOOTSTRAP--> <link href="js/bootstrap.min.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<?php require "config/config.php"; $chat = new Chat(); switch ($_POST['acao']) { case 'inserir': $chat->excluir(); $chat->setNome($_COOKIE['nome']); $chat->setMensagem(filter_input(INPUT_POST, 'mensagem')); if ($chat->inserir()) { printf('<p class="bg-primary eu pull-right">[%s] - %s</p><br>', $chat->getNome(), $chat->getMensagem()); } break; case 'atualizar': foreach ($chat->listar() as $v) { $ativo = $v['nome'] == $_COOKIE['nome'] ? 'class="bg-primary eu pull-right"' : 'class="bg-warning ele pull-right;"'; printf('<br><p %s> %s Disse: " %s "</p><br>', $ativo, $v['nome'], $v['mensagem']); } break; }