<?php
if( !empty($_POST['clear'])){
$my_file = 'file.txt';
if(is_file($my_file)){
unlink($my_file);
}
}
if( !empty($_POST['Name'])){
$newData = "<Font Color=red>";
$newData .= "<b>Name:</b>" ;
$newData .= $_POST['Name'];
$my_file = 'file.txt';
$handle = fopen($my_file, 'a+') or die('Cannot open file: '.$my_file);
$data = fwrite($handle,$newData);
}
if( !empty($_POST['Farbe'])){
$newData = "<b>Nachricht:</b>" ;
$newData .= "<Font Color=";
$newData .= $_POST['Farbe'];
$newData .= "></>";
$my_file = 'file.txt';
$handle = fopen($my_file, 'a+') or die('Cannot open file: '.$my_file);
$data = fwrite($handle,$newData);
}
if( !empty($_POST['chat'])){
$newData = $_POST['chat'];
$newData .= "<br>";
$my_file = 'file.txt';
$handle = fopen($my_file, 'a+') or die('Cannot open file: '.$my_file);
$data = fwrite($handle,$newData);
}
?>
<!DOCTYPE html>
<html lang="de">
<meta http-equiv="refresh" content="10; URL=/chat12.php">
<head>
<meta charset="utf-8">
<h1><Font Color=orange></>Chat</h1>
<title>Chat</title>
<link rel="stylesheet" href="main.css" type="text/css"/>
<script src="chat.js"></script>
</head>
<body>
<form id="form1" method="post" action="">
<textarea id="Name" rows="3" name="Name" cols="10" placeholder="Bitte Name eingeben..."></textarea>
<textarea id="Farbe" rows="3" name="Farbe" cols="50" placeholder="Bitte Farbe eingeben(optional[Farben:red(standard),green,lime,orange,yellow,black,blue])..."></textarea>
<textarea id="area2" rows="10" name="chat" cols="50" placeholder="Schreibe deinen text hier....."></textarea>
<br>
<input type="submit" id="button" value="Senden">
</form>
<form id="form1" method="post" action="">
<!-- <input type="submit" name="clear" id="button" value="Lösche Verlauf"> Das kannst du optional dazu tun -->
</form>
<hr>
<h2>Nachrichten:</h2>
<?php
$my_file = 'file.txt';
if(is_file($my_file)){
$handle = fopen($my_file, 'r') or die('Cannot open file: '.$my_file);
$data = fread($handle,filesize($my_file));
echo nl2br($data);
}
?>
<hr>
</body>
</html>