Membuat shoutbox dengan PHP

By in Tutorial on June 28, 2015
Tutorial membuat Shout box

Tutorial membuat Shout box

Langsung aja ya, Silahkan COPAS kode di bawah ini, lalu simpan dalam format [.php], lalu buat file kosong dengan nama msg formatnya [.txt]

Jika sudah, upload ke webserver Anda dalam satu folder.
KODE :

<?php// Tutorial membuat Shout box

?>

<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Shoutbox</title>
<style>
body
{
background-color: #eee;
font-family: Verdana;
font-size: 11px;
color: #000;
padding:4px;
}
</style>
<script>
function check()
{
var tex = document.ssa.message.value;
var len = tex.length;
var rem = 120-len;
if(len >= 120)
{
tex = tex.substring(0,120);
document.ssa.message.value =tex;
return false;
}
if(rem<0)
rem=0;
document.ssa.rem.value =rem;
}
</script>
</head>
<body>
<form name=ssa action=”” method=”post”>
<b>NAMA :</b><br>
<input type=”text” name=”person” size=”20″ value=”<?php echo $person; ?>”><br>
<b>PESAN :</b><br>
<textarea name=”message” rows=”2″ cols=”32″ wrap=”physical” onkeyup=”check()”></textarea><br>
<font color=”#0000ff”>Sisa huruf : </font><input type=”text” name=”rem” size=”3″ readonly value=”120″>
<input type=”submit” value=”Kirim atau perbarui”></form>
<br>

<?
$person = str_replace (“\n”,” “, $person);
$person = str_replace (“User”,”Anonim”, $person);
$person = str_replace (“Admin”, “Anonim”, $person);
$person = stripslashes ($person);
$chat_file_ok = “msg.txt”;
$chat_lenght = 10;
$max_single_msg_lenght = 100000;
$max_file_size = $chat_lenght * $max_single_msg_lenght;
$file_size= filesize($chat_file);
if ($file_size > $max_file_size)
{
$lines = file($chat_file_ok);
$a = count($lines);
$u = $a – $chat_lenght;
for($i = $a; $i >= $u ;
$i–)
{
$msg_old = $lines[$i] . $msg_old;
}
$deleted = unlink($chat_file_ok);
$fp = fopen($chat_file_ok, “a+”);
$fw = fwrite($fp, $msg_old);
fclose($fp);
}
$url = “http://nubo.ga/s”;
$msg = str_replace (“\n”,” “, $message);
$msg = str_replace (“:/)”, “<img src=\”$url/smileys/4.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“:/(“, “<img src=\”$url/smileys/8.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“:/*”, “<img src=\”$url/smileys/6.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“:/D”, “<img src=\”$url/smileys/3.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“:/P”, “<img src=\”$url/smileys/7.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“Ok”, “<img src=\”$url/smileys/sip.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“ok”, “<img src=\”$url/smileys/sip.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“Welcome”, “<img src=\”$url/smileys/welcome.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“welcome”, “<img src=\”$url/smileys/welcome.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“test”, “<img src=\”$url/smileys/cool.gif\” alt=\”*\” />”, $msg);
$msg = str_replace (“f-uc-k”, “<img src=\”$url/smileys/x.gif\” alt=\”*\” />”, $msg);
$msg = stripslashes ($msg);
if ($msg != “”)
{
$fp = fopen($chat_file_ok, “a+”);
$fw = fwrite($fp, “\n<font color=black><b>$person :</b></font> $msg<hr>”);
fclose($fp);
}
$lines = file($chat_file_ok);
$a = count($lines);
$u = $a – $chat_lenght;
for($i = $a;
$i >= $u ;
$i–)
{
echo $lines[$i] . “”;
}
?>
<br>
</body>
</html>

 

Download filenya dalam bentuk “RAR” di link bawah ini :
Membuat shoutbox dengan PHP

Selamat mencoba.



Baca juga :

Bagikan ini ke :

Leave a Reply