Skip to content

Instantly share code, notes, and snippets.

@iGusev
Created September 25, 2014 20:10
Show Gist options
  • Save iGusev/3aaaaa161a95cda33729 to your computer and use it in GitHub Desktop.
Save iGusev/3aaaaa161a95cda33729 to your computer and use it in GitHub Desktop.
php-chat
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<meta http-equiv="refresh" content="2">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.chat-body {
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 1px dotted #B3A9A9;
}
.text-muted span.glyphicon-time {
margin-right: 5px;
}
</style>
</head>
<body>
<div class="container-fluid">
<?php echo file_get_contents('text'); ?>
</div>
</body>
</html>
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Chat Challenge</title>
<link rel="icon" type="image/x-icon" href="/favicon.ico"/>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.container {
width: 600px;
}
.chat-messages {
margin-top: 20px;
height: 600px;
}
.chat-form {
height: 180px;
}
iframe {
width: 100%;
height: 100%;
border: 0;
}
</style>
</head>
<body>
<div class="container">
<div class="row chat-messages">
<iframe class="messages" src="chat.php"></iframe>
</div>
<div class="row chat-form">
<form role="form" action="save.php">
<div class="form-group">
<input type="text" class="form-control" name="name" placeholder="Ваше имя"
value="<?php echo $_SESSION['name']; ?>">
</div>
<div class="input-group">
<input type="text" class="form-control" name="text" placeholder="Сообщение">
<span class="input-group-btn">
<input type="submit" class="btn btn-default" id="btn-chat" value="Послать"/>
</span>
</div>
</form>
</div>
</div>
</body>
</html>
<?php
session_start();
if($_REQUEST['name'] && $_REQUEST['text']) {
$name = strip_tags($_REQUEST['name']);
$text = strip_tags($_REQUEST['text']);
ob_start();
include('template.php');
$out = ob_get_clean();
file_put_contents('text', $out, FILE_APPEND);
$_SESSION['name'] = $name;
}
header('Location: '.$_SERVER['HTTP_REFERER']);
<div class="chat-body clearfix">
<div class="header">
<small class=" text-muted"><span class="glyphicon glyphicon-time"></span><?php echo date('d.m.Y H:i:s') ?></small>
<strong class="pull-right primary-font"><?php echo $name; ?></strong>
</div>
<p>
<?php echo $text; ?>
</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment