March 5, 2013

Universal Forum Version 3


Version 3 of a php microforum that I wrote, consisting of a single self-referencing script. With just the click of a button the script appends name and comment field data to itself, then refreshes a second later. There are lots of other subtle features, but instead of blathering on about them here I'll let you examine them directly in the complete source code:


<?php
date_default_timezone_set('America/Los_Angeles');
error_reporting (E_ALL ^ E_NOTICE);
echo "<!doctype html><html><head>
<meta http-equiv='content-type' content='text/html; charset=UTF-8'><title>Universal Forum v3</title>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
<style>
body{margin:0%;padding:0%;background-color:white;font-family: 'Source Sans Pro', sans-serif;font-size:20px;}
.form{margin:2%;}
#textarea{font-family: 'Source Sans Pro', sans-serif;font-size:20px;}
#button{
padding-left:1%;padding-right:1%;padding-top:3%;padding-bottom:3%;vertical-align:top;font-family: 'Source Sans Pro', sans-serif;font-size:40px;}
.bar{padding:1%;background-color:black;text-align:center;font-weight:bold;}
.bubble{margin:1%;padding:1%;border:1px solid whitesmoke;border-radius:3px;background-color:ghostwhite;}
</style>
</head><body>
<div class='form'><form action='index.php' method='post'><input type='text' name='x' placeholder='name' id='textarea';'><br><textarea rows='6' cols='30' wrap='virtual' name='y' placeholder='comment' id='textarea';'></textarea><input type='submit' value='✎post' id='button'></form></div>";
$file = "index.php";
$name = fopen($file, 'a') or die("fail");
if ($_POST["y"]=="")
echo "<div class='bar'><font color='yellow'>you must enter something to post</font></div>";
else
{
echo "<div class='bar'><font color='lime'>comment posted!</font></div>";
fwrite($name, $string);
$string = "<div class='bubble'><font color='blue'><b>";
fwrite($name, $string);
$string = strip_tags($_POST["x"]);
fwrite($name, $string);
$string = "</b></font> ";
fwrite($name, $string);
$string = "<font color='silver'>(";
fwrite($name, $string);
$string = date("y.m.d H:i:s", time());
fwrite($name, $string);
$string = ")</font><br>❝";
fwrite($name, $string);
$string = strip_tags($_POST["y"]);
fwrite($name, $string);
$string = "❞</div>";
fwrite($name, $string);
fclose($name);
if ($_POST["y"]=="")
echo "";
else
{
echo('<meta http-equiv="refresh" content="1">');
}
}
?>

No comments: