PHP Chat Application w/o SQL

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

PHP Chat Application w/o SQL

Post by fresh »

Information:
Title: BLS-CHAT
Author: blsoftware
Copyright: 2004 Black List Software
Description: Online PHP Chat application
Installation: 10 minutes

Prerequisites:
a. Folder named: log
b. File named: session.txt
c. PHP installed

Features:
a. DoS protection
b. Built in commands
c. SQL FREE

Bugs:
a. Log file must be refreshed manually BEFORE chatting takes place

Code: Select all

<?php
$user = $_POST&#1111;'uname'];
$userx = $_COOKIE&#1111;$user];
setcookie($user, $user);
switch($user) &#123;
case "":
$note = "&nbsp;<font size=2><b>Error:</b> Username Not Specified!</font>";
break;
case "cleanitup":
$user = "";
$clean = "";
$fx = fopen("log/session.txt","w");
fputs($fx,$clean."\n");
fclose($fx);
$note = "&nbsp;<font size=2><b>Status:</b> Command Completed Successfully!</font>";
break;
default:
$file = "log/session.txt";
$lines = count(file($file));
if ($lines >= 16) &#123;
$clean2 = "";
$fx2 = fopen("log/session.txt","w");
fputs($fx2,$clean2."\n");
fclose($fx2);
$message = $_POST&#1111;'message'];
$message = strtolower($message);
$fp = fopen("log/session.txt","ab");
fputs($fp,"\n".$user.": ".$message."\n_________________________________________________________________________\n");
fclose($fp);
$note = "&nbsp;<font size=2><b>Status:</b> Transmission Completed Successfully!</font>";
&#125; else &#123;
$message = $_POST&#1111;'message'];
$message = strtolower($message);
$fp = fopen("log/session.txt","ab");
fputs($fp,"\n".$user.": ".$message."\n_________________________________________________________________________\n");
fclose($fp);
$note = "&nbsp;<font size=2><b>Status:</b> Transmission Completed Successfully!</font>";
&#125;&#125;
?>
<html>
<head>
<title>BLS-CHAT v1.0.0 :: Black List Software</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script>
function doIt(_v) &#123;
if (_v==1) &#123;
document.all.console.src="http://blah.com/log/session.txt";
reLoad();
&#125;&#125;
function reLoad() &#123;
setTimeout("doIt(1)",3000)
&#125;
</script>
</head>
<body bgcolor=#ffffff onload="doIt(1)">
<form name="main" action="<?php $_SERVER&#1111;'PHP_SELF']; ?>" method="post">
<center>
<div align="right" style="background:#D3E2F6; width:600; border:#000000 1px solid;">
<table width=599 border=0 cellpadding=0 cellspacing=0>
<td width=70%><?php echo "".$note.""; ?></td>
<td>
<font size=2><b>Username:</b></font>&nbsp;
</td>
<td>
<input type="text" style="width:150;" name="uname" value="<?php echo "".$userx.""; ?>">
</td>
</table>
</div>

<table width=600 border=0 cellpadding=0 cellspacing=0>
<td width=100%>
<iframe name="console" width=598 height=303 src="http://blah.com/log/session.txt"></iframe>
</td>
</table>

<div style="border:#000000 1px solid; width:600;">
<table width=100% border=0 cellpadding=0 cellspacing=0>
<td width=100% bgcolor=#D3E2F6>
<input type="text" name="message" maxlength="60" style="width:100%; height:19; font-size:10px;">
</td>
<td>
<input type="submit" value="Submit" name="sub" style="font-size:10px;">
</td>
</table>
</div>
<br><br>
<font size=1>BLS-CHAT v1.0.0 &copy; 2004 Black List Software, All rights reserved</font>
</center>
</form>
</body>
</html>
If anyone has any questions, comments, or concerns, please feel free to post those here. I will be more than happy to assist you if you are having trouble running this properly on your server. Keep in mind that this code is not perfect and is only a supplement for those without SQL access. If you have SQL and available DB's, you should use SQL instead; however, if you happen to not have the extra SQL DB or SQL at all, this code is your alternative to online chatting. Something obvious that I'd like to quickly point out is that you are going to have to edit the syntax a bit such as, providing your own information like web address, etc.. Other than that, further configuration is completly optional.

enjoy :)
Post Reply