The Mudcat Café TM
Thread #93749   Message #1808632
Posted By: GUEST,Jon
13-Aug-06 - 06:34 AM
Thread Name: BS: mudchat, why is there never anyone there
Subject: RE: BS: mudchat, why is there never anyone there
As a curiosity item, I was discussing various chats elsewhere earlier this year and cobbled up a version of a "browser refresh" type while tring to eplain them. This is very crude but it actually does work as a chat.


login.php: Logon to the chat.
Code:

<html>
<body>
<form action="main.php" method="post">
User Name:
<input name="username">
<input type="submit" value="Log In">
</form>
</body
</html>


main.php. Main page for frames & announce someone to the room
Code:

<?
if (isset($_POST["username"]))
   {
   require("db.php");
   $SQL="INSERT INTO message (username, message)
   VALUES ('System', '" . $_POST["username"] . " has joined the room')";
   mysql_query($SQL);
   }
?>
<html>
<frameset rows = "85%, 15%" />
<frame src ="message.php" />
<frame src = "input.php?username=<?echo $_POST["username"]?>" />
</frameset>
</html>


message.php: Display the messages
Code:

<html>
<head>
<meta http-equiv="refresh" content="5;url=message.php">
</head>
<body>
<?
require("db.php");
$SQL="Select * FROM message ORDER BY ID DESC LIMIT 20";
$result = mysql_query($SQL);
$text = mysql_fetch_array($result);
while (!($text==0))
   {
   echo $text["username"] . ": ";
   echo $text["message"] . "<br>\r\n";
   $text = mysql_fetch_array($result);
   }
?>
</body>
</html>


input.php: user message input.
Code:

<?
if (isset($_POST["send"]))
   {
   require("db.php");
   $SQL = "INSERT INTO message (username, message)
   VALUES ('" . $_POST["username"] . "', '" . $_POST["message"] . "')";
   mysql_query($SQL);
   }
?>
<html>
<head>
</head>
<body>   
<form action="input.php" method="post">
<input type="hidden" name="username" value="<?echo $_REQUEST["username"]?>">
<input name="message" size="80" >
<input type="submit" name="send" value="send">
</form>
</body>
</html>