Formular als chat, aus einer datei !!! (noch nicht fertig)
Andreas
- meinung
0 Schuer
<?php
//File: "formchat.php" - (4.580 Bytes)
//From: "Andreas" - (2004)
$textfile = @fopen("text.txt", "a+");
function input_to_output()
{
if (!empty($_REQUEST['input']) && !isset($_REQUEST['options'])) {
$textfile = @fopen("text.txt", "a+");
fwrite($textfile, $_REQUEST['nick']. ": ". $_REQUEST['input']. "\r\n");
unset($_REQUEST['input']);
}
else {
echo rtrim($_REQUEST['output']). "\n";
return true;
}
$textfile = file("text.txt");
foreach ($textfile as $line => $_REQUEST['output']) {
if ($line < 9) {
echo $_REQUEST['output'];
continue;
}
else {
$reset = 0;
$textfile = file("text.txt");
unset($textfile[$reset]);
$set = implode($textfile);
$textfile = @fopen("text.txt", "w+");
fwrite($textfile, $set);
echo $_REQUEST['output'];
return true;
}
}
}
?>
<html>
<head>
<title>FormChat</title>
<style language="stylesheet" type="text/css">
<!--
h1 {
font-family:arial; font-size:21pt;
font-weight:bold;
}
hr.black {
width:445px; text-align:left;
border:1px solid #000000;
}
hr.silver {
width:445px; text-align:left;
border:1px solid #C0C0C0;
}
div.normal, input.input {
font-family:arial; font-size:10pt;
font-weight:bold;
}
div.small {
font-family:arial; font-size:8pt;
font-weight:bold;
}
div.options {
font-family:arial; font-size:10pt;
font-weight:bold; margin-bottom:2px;
}
table.options {
border:2px dashed #C0C0C0;
}
input.options, select.options {
font-family:arial; font-size:8pt;
}
input.button {
width:65px; font-family:arial;
font-size:10pt; font-weight:bold;
}
textarea.output {
width:82%; overflow-y:hidden;
cursor:crosshair;
}
textarea.nicks {
width:17%; overflow-y:hidden;
cursor:crosshair;
}
//-->
</style>
</head>
<body onLoad="document.chat.input.focus();" onContextMenu="return false">
<h1>FormChat</h1>
<form action="formchat.php" method="post" name="chat">
<?php if (isset($_REQUEST['options'])) { ?>
<hr class="silver">
<?php } else { ?>
<hr class="black">
<?php } ?>
<table border="0" width="445" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3">
<div> </div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="normal">Output:</div>
</td>
<td>
<div class="normal">User:</div>
</td>
</tr>
<tr>
<td colspan="3">
<textarea rows="10" name="output" class="output" readonly>
<?php input_to_output(); ?>
</textarea>
<textarea rows="10" name="nicks" class="nicks" readonly>
<?php echo $_REQUEST['nick']. "\n"; ?>
</textarea>
</td>
</tr>
<tr>
<td colspan="3">
<div> </div>
</td>
</tr>
<tr>
<td colspan="3">
<div class="normal">Input:</div>
</td>
</tr>
<tr>
<td width="45%">
<input type="text" maxlength="34" name="input" size="35">
</td>
<td width="34%" align="left">
<input type="submit" value="Send" class="input"><input type="reset" value="Delete" class="input">
</td>
<td align="right">
<?php if (!isset($_REQUEST['options'])) { ?>
<input type="submit" name="options" value="Options" class="button">
<?php } else { ?>
<input type="submit" name="ok" value="OK" class="button">
<?php } ?>
</td>
</tr>
</table>
<br>
<?php if (isset($_REQUEST['options'])) { ?>
<hr class="black">
<div class="options">Options:</div>
</table>
<table width="100" cellpadding="0" cellspacing="5" class="options">
<tr>
<td width="100">
<div class="small">Name:</div>
</td>
<td>
<input type="text" maxlength="8" size="6" name="nick" value="<?php echo $_REQUEST['nick']; ?>" class="options">
</td>
</tr>
<tr>
<td>
<div class="small">Chats:</div>
</td>
<td>
<select name="chats" class="options">
<option>Chat-1</option>
<option>Chat-2</option>
<option>Chat-3</option>
</select>
</td>
</tr>
<tr>
<td>
<div class="small">Infos:</div>
</td>
<td>
<input type="checkbox" name="infos" checked>
</td>
</tr>
</table>
<br>
<hr class="silver">
<?php } else { ?>
<hr class="silver">
<input type="hidden" name="nick" value="<?php echo $_REQUEST['nick']; ?>">
<?php } ?>
</form>
</body>
</html>
Hallo!
<?php
..
?>
Du solltest noch die Frage maskieren, wenn du sie per echo ausgibst.
Gruß,
_Dirk