Added code
This commit is contained in:
commit
46979c3b5a
26
index.php
Normal file
26
index.php
Normal file
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Chat</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="form">
|
||||
<form action="send.php" method="get">
|
||||
Nickname: <input type="text" name="userName"><br>
|
||||
Message:<br>
|
||||
<input type="text" name="userMessage"><br>
|
||||
<input type="submit" value="Send">
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div id="messages">
|
||||
<iframe src="messages.php" id="messages">
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
15
messages.php
Normal file
15
messages.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$message_file = fopen("messages.csv", "r");
|
||||
while (($messages = fgetcsv($message_file)) !== FALSE) {
|
||||
if ($messages[0] == "") {
|
||||
$userName = "anon";
|
||||
} else {
|
||||
$userName = $messages[0];
|
||||
}
|
||||
echo("<p style='color: red;'>" . $userName . " says:</p><p>" . $messages[1] . "</p><p style='color: red;'>At: " . $messages[2] . "</p><hr>");
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
window.scrollTo(0,document.body.scrollHeight);
|
||||
</script>
|
||||
<?php return; ?>
|
21
send.php
Normal file
21
send.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
//set error reporting
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if ($_GET["userMessage"] == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
$dateToWrite = date("Y-m-d H:i:s");
|
||||
|
||||
$array = array($_GET["userName"], $_GET["userMessage"], $dateToWrite, microtime());
|
||||
|
||||
//open csv file
|
||||
//format is "user name", "user message", "Y-m-d H:i:s", "microtime"
|
||||
fputcsv(fopen("messages.csv", "a+"), $array);
|
||||
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
?>
|
Loading…
Reference in New Issue
Block a user