Login | Register
Nerd ParadiseArtisanal tutorials since 1999
Someone in the IRC room spoke of a forum that was once written in under 2 KB of code. A simple minimalistic forum that had no user account system, but still had enough functionality to support the notion of threads and posts.

Almost jokingly, I said I bet I could do it in 1KB. But I gave it a shot anyway, and behold, here it is, slightly under 1KB at 964 bytes!

(line breaks inserted to prevent page formatting weirdness)
<html><body><h1>1KB Forum</h1><?mysql_connect('localhost','username','********');mysql_
select_db('d');extract($_REQUEST);$v=intval($v);$i=0;$q='mysql_query';$f='mysql_fetch_r
ow';$n='mysql_num_rows';$x='<input type="';$s="SELECT*FROM";$t='CREATE TABLE IF NOT EXI
STS t(i INT AUTO_INCREMENT,a INT,b TEXT,KEY(i))';$h='htmlspecialchars';$q($t);$q(str_re
place('t','p',$t));$l=' ORDER BY';$o='';$u='INSERT INTO';$c="b)VALUES('";if($b){if(!$v)
$q("$u t($c$e')");$v=max($v,mysql_insert_id());$q("$u p(a,$c$v','$b')");}if($v){$t=$q("
$s p WHERE a=$v$l i");echo'<a href="f.php">Back</a>';for(;$i<$n($t);++$i){$r=$f($t);ech
o'<hr/>'.nl2br($h($r[2]));}}else{$t=$q("$s t$l-i");for(;$i<$n($t);++$i){$r=$f($t);echo'
<a href="f.php?v='.$r[0].'">'.$h($r[2]).'</a><br/>';}$o='Title:'.$x.'text"name="e"/><br
/>';}echo'<hr/>Post:<form action="f.php"method="post">'.$x.'hidden"name="v"value="'."$v
\"/>$o<textarea name=\"b\"></textarea>$x";?>submit"name="w"value="Post"/></form></body>
</html>


It even creates the schema the first time you access the script. Of course you have to first have a database called 'd' and update the MySQL account credentials at the beginning to match your own. Magic quotes need to be enabled to prevent SQL injection!

I have this script running here if you want to see what it looks like in action. You'll have to pardon the graffiti, though. As you can imagine there is no such thing as a moderator on this forum.