![]() |
|
PHP shoutbox with database - Printable Version +- HN-Community (https://hacker-newbie.org) +-- Forum: Miscellaneous (https://hacker-newbie.org/forum-86.html) +--- Forum: Coding/Programing (https://hacker-newbie.org/forum-19.html) +---- Forum: Web Programing (https://hacker-newbie.org/forum-38.html) +---- Thread: PHP shoutbox with database (/thread-10358.html) |
PHP shoutbox with database - killerbyte - 10-03-2011 ketemu lagi sama ane (n00b blogger) ![]() lagi iseng maenan shoutbox, penasaran juga gimana cara buatnya, akhirnya ketemu juga scriptnya, ![]() langsung disedot ini scriptnya Code: <?php
//------ Edit Below This Line ------//
define('SHOUTBOX', 'shoutbox');
$host = 'localhost';
$dbuser = 'username'; // Username to access database.
$dbpass = 'password'; // Password to access database.
$dbname = 'database'; // Database name.
$allowed_tags = '<b><i><u><a>';
//------ Edit Above This Line ------//
mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
function clean_string($string, $tags = '')
{
$string = trim($string);
$string = str_replace("\'", "''", $string);
return $string;
}
?>
<style type="text/css">
.shoutbox {
margin: 0px;
padding: 0px;}
.shoutbox a, a:visited {
color: 6E7A8A;
font-size: 12px;
font-weight: bold;
text-decoration: none;}
.shoutbox a:hover {
color: 6E7A8A;
text-decoration: underline;}
.shoutbox input, select, textarea {
border: 1px solid silver;}
.form {
font-size: 12px;}
#name1 {
background-color: E0E0E0;
color: 666666;
font-size: 12px;}
#content1 {
background-color: E0E0E0;
font-size: 12px;}
#name2 {
background-color: F3F3F3;
color: 666666;
font-size: 12px;}
#content2 {
background-color: F3F3F3;
font-size: 12px;}
</style>
<?php
switch($_GET['p'])
{
case 'box':
echo "<body class=\"shoutbox\">\n<table cellpadding=\"2\">";
$result = mysql_query("SELECT * FROM " . SHOUTBOX . " ORDER BY id DESC") or die(mysql_error());
for ($i = 1; $i <= ($row = mysql_fetch_assoc($result)); $i++)
{
$nameid = (!($i % 2)) ? 'name1' : 'name2';
$contentid = (!($i % 2)) ? 'content1' : 'content2';
$name = strip_tags(stripslashes($row['name']), $allowed_tags);
$website = strip_tags(stripslashes($row['website']), $allowed_tags);
$content = strip_tags(stripslashes($row['content']), $allowed_tags);
echo '<tr><td id="' . $nameid . '" width="50" align="right">',
((!empty($row['website'])) ? "<a href=\"$website\">$name</a>" : $name),
'</td><td id="' . $contentid . '" width="170">' . $content . "</td></tr>\n";
}
echo "</table>\n</body>";
break;
default:
echo '<div class="shoutbox">';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['name']) && !empty($_POST['content']))
{
$name = clean_string($_POST['name']);
$website = clean_string($_POST['website']);
$website = (!empty($website) && $website != 'http://') ? (!eregi('^http://', $website) ? 'http://' . $website : $website) : '';
$content = nl2br(clean_string($_POST['content'], '<a>'));
mysql_query("INSERT INTO " . SHOUTBOX . " (name, website, content) VALUES ('$name', '$website', '$content')") or die(mysql_error());
}
echo '<iframe src="' . basename($_SERVER['PHP_SELF']) . '?p=box" width="260" height="285"></iframe>
<form method="post"><table class="form">
<tr><td align="right">Name:</td><td><input type="text" name="name" size="10"></td></tr>
<tr><td align="right">Website:</td><td><input type="text" name="website" value="http://" size="10"></td></tr>
<tr><td align="right">Message:</td><td><textarea name="content" rows="3" cols="20"></textarea></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Submit"></td></tr>
</table></form>', "\n</div>";
break;
}
?>upload k hosting atau masukin k folder localhost (untuk coba-coba) buka phpmyadmin localhost atau hostingnya kalo mau di gabung sama database lain tinggal jalanin query ini Code: CREATE TABLE shoutbox (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50),
website VARCHAR(150),
content VARCHAR(255),
PRIMARY KEY (id)
);lalu jalankan query diatas jika sudah edit script diatas Code: $host = 'localhost';
$dbuser = 'username'; // ganti username database
$dbpass = 'password'; // ganti dengan password database
$dbname = 'database'; // ganti databasenyawala simple shoutbox pun jadi ![]() tambahan dari kk febrian (10-05-2011, 07:48 PM)febrian Wrote: sedikit tambahan dari wong dewa RE: PHP shoutbox with database - Up_ - 10-04-2011 wah keren bro..!! lumayan buat nambah2 shoutbox di web RE: PHP shoutbox with database - Gelby - 10-04-2011 wah... bagus nih untuk mengkreasikan blog... ijin comot...!!!
RE: PHP shoutbox with database - killerbyte - 10-04-2011 sayang, nggak bisa dipasang di blogspot, cz ini kan butuh php dan database gak tau juga kalo kk kk yg udah jago mah
RE: PHP shoutbox with database - Up_ - 10-04-2011 bisa kok di blogspot.. - buat PHP SHOUTBOX di hotsing gratis... - trus masukin kode HTMLnya di widget blogspot. RE: PHP shoutbox with database - febrian - 10-05-2011 sedikit tambahan dari wong copo masukan scrip berikut dibawah scrit "$content = strip_tags(stripslashes($row['content']), $allowed_tags);" *tanpa kutip PHP Code: $content = str_replace(":)", "<img src=\"emoticons/smiley-happy014.gif\">", $content);
$content = str_replace(":(", "<img src=\"emoticons/sedih.gif\">", $content);
$content = str_replace(":bahagia:", "<img src=\"emoticons/bahagia.gif\">", $content);
$content = str_replace(":bingung:", "<img src=\"emoticons/bingung.gif\">", $content);
$content = str_replace(":bonyok:", "<img src=\"emoticons/bonyok.gif\">", $content);
$content = str_replace(":culas:", "<img src=\"emoticons/culas.gif\">", $content);
$content = str_replace(":ehm:", "<img src=\"emoticons/ehm.gif\">", $content);
$content = str_replace(":hantu:", "<img src=\"emoticons/hantu.gif\">", $content);
$content = str_replace(":D", "<img src=\"emoticons/huwaa.gif\">", $content);
$content = str_replace(":love:", "<img src=\"emoticons/love.gif\">", $content);
$content = str_replace(":*", "<img src=\"emoticons/kiss.gif\">", $content);
$content = str_replace(":maho:", "<img src=\"emoticons/maho.gif\">", $content);
$content = str_replace(":mantab:", "<img src=\"emoticons/mantab.gif\">", $content);
$content = str_replace(":marah:", "<img src=\"emoticons/marah.gif\">", $content);
$content = str_replace(":perimaho:", "<img src=\"emoticons/perimaho.gif\">", $content);
$content = str_replace(":santet:", "<img src=\"emoticons/santet.gif\">", $content);
$content = str_replace(":sedih:", "<img src=\"emoticons/sedih.gif\">", $content);
$content = str_replace(":sombong:", "<img src=\"emoticons/sombong.gif\">", $content);
$content = str_replace(":tidak:", "<img src=\"emoticons/tidak.gif\">", $content);
$content = str_replace(":what:", "<img src=\"emoticons/what.gif\">", $content);
$content = str_replace(":wow:", "<img src=\"emoticons/wow.gif\">", $content);
ss ![]() note: str_replace berfungsi untuk menghapus kata <img src=\"emoticons/wow.gif\"> lokasi gambar jadi inti-nya script ini untuk merubah tulisan yg berbentuk smile menjadi sebuah gambar low ada yg error boleh ditanyakan RE: PHP shoutbox with database - jaka69 - 10-06-2011 emmmmmmmmmmmmm.....................bagus jg neh....lanjutkan feb....... mantap.. :_) RE: PHP shoutbox with database - febrian - 10-06-2011 (10-06-2011, 12:26 AM)jaka69 Wrote: emmmmmmmmmmmmm.....................bagus jg neh....lanjutkan feb....... oke bang.. ini jga gi berexperimen membuat komentar mengunakan smile... tar rencan-nya bulan depan web baru bakal saya terbitkan |