File : chatphp.txt. ID : 9104
Skin : Default | Sons-of-obsidian | Sunburst | Highlighter | Frame
<? 
session_start();
$tot_line = 15;
$refresh = 600; // 600 = 10 minutes
$program = "chat.php";
if (isset($_SESSION["nm"])) {
  if (isset($_POST['nm'])) {
	$_POST['mg'] = str_replace("\r\n","<dd>",$_POST['mg']);
    if ($_SESSION["mg"] == $_POST['mg']) $_POST['mg'] = ""; 
    $_SESSION["mg"] = $_POST['mg']; 
    $_SESSION["nm"] = $_POST['nm']; 
  } else {
    $_POST['mg'] = "";
  }
} else {
  if (isset($_POST['nm'])) {
    $_POST['mg'] = str_replace("\r\n","<dd>",$_POST['mg']);
	$_SESSION["mg"] = $_POST['mg']; 
	$_SESSION["nm"] = $_POST['nm'];
  }
}
if (isset($_POST['clear'])) {
  $file=fopen("chat.txt","w");  
  for ($i=1;$i<=$tot_line;$i++) fputs($file,"");
  fclose($file);
  echo "<meta http-equiv=refresh content='0;url=".$program."'>";
  exit;
}
?>
<html><head><title>ห้องถาม-ตอบ</title>
<meta http-equiv=content-type content="text/html; charset=windows-874">
<meta http-equiv=refresh content="<?=$refresh?>;url=<?=$program?>">
</head>
<body topmargin=0 leftmargin=0 bgcolor=#ddffdd><font color=black face="microsoft sans serif" size=0>
<form action=<?=$program?> method=post><pre><textarea style="background=#ffffdd;" name=mg cols=60 rows=3 wrap=off><? 
if (isset($_POST['mg'])) { echo ""; } else { echo "พิมพ์ข้อความของท่านที่นี่"; }
echo "</textarea><br><input style='background=#dddddd;' name=nm size=8 value='"; 
if (isset($_SESSION['nm'])) { echo $_SESSION['nm']; } else { echo "ชื่อท่าน"; } 
echo "'> <input type=submit value=Send> <input type=submit value=Refresh> <input type=submit value='Clear All' name=clear> <input type=button onclick={window.open('".$program."');} value=Enlarge>";
if (isset($_POST['mg']) and strlen($_POST['mg']) > 2 
    and isset($_POST['nm']) and strlen($_POST['nm']) > 1 
	and strlen($_POST['mg']) < 1000 and strlen($_POST['nm']) < 20 
	and $_POST['mg'] != "พิมพ์ข้อความของท่านที่นี่" ) {
  $ar=file("chat.txt");
  $file=fopen("chat.txt","w");  
  for ($i=1;$i<=count($ar)-1;$i++) {
    fputs($file,"$ar[$i]");
  }
  fputs($file,"<font color=red><a title='" . date("d/m/y") . " " .$_SERVER["REMOTE_ADDR"] . "'>".date("H:i:s")."</a></font> <b>");
  fputs($file,substr($_POST['nm'],0,15) ."</b> :". $_POST['mg'] . chr(13).chr(10));
  if (count($ar) < $tot_line) {
    for ($j=count($ar);$j<=$tot_line;$j++) {
      fputs($file,"-"  . chr(13).chr(10));
    }
  }
  fclose($file);
}
echo "<br>[".date("d/m/y H:i:s")."]<br>";  
$ar=file("chat.txt");
for ($i=count($ar)-1;$i>=0;$i--) {
  echo "$ar[$i]";
}
?>
<br>version 1.480929c
</form>
</body></html>