1.
Software:
·
WampServer 2.2
·
Apache 2.2.21
·
PHP 5.3.10
·
MySQL 5.5.20
2.
Buat database: ikhbaar
Column
|
Type
|
Length
|
Extra
|
id
|
Integer
|
11
|
Auto_Increment
|
article_id
|
Integer
|
11
|
|
name
|
Varchar
|
50
|
|
email
|
Varchar
|
100
|
|
comment
|
Text
|
||
date
|
Datetime
|
4.
Buat file: 7komentar_proses.php
Ketik script berikut:
<?php
function sql_connect($dbhost, $dbuser, $dbpass,
$dbname) {
$dbconn
= mysql_connect($dbhost, $dbuser, $dbpass);
if($dbconn)
{
$dbselect
= mysql_select_db($dbname);
if(!$dbselect)
{
mysql_close($dbconn);
$dbconn
= false;
}
}
return
$dbconn;
}
function check_email($email) {
return
preg_match("/^([_a-zA-Z0-9-+]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,6})$/"
, $email) ? $email : FALSE;
}
function create_code() {
$temp
= explode(" ", microtime());
$recnum
= str_replace(".", "", $temp[1].$temp[0]);
$rcode
= hexdec(md5($recnum));
$code
= substr($rcode, 2, 6);
$_SESSION['tmp']['captcha'][0]
= $recnum;
$_SESSION['tmp']['captcha'][1]
= $code;
return
array($recnum, $code);
}
function verify_code($rec_num, $checkstr) {
if
($_SESSION['tmp']['captcha'][0] == $rec_num) {
$code
= $_SESSION['tmp']['captcha'][1];
$_SESSION['tmp']['captcha']
= '';
return
($checkstr == $code);
}
return
FALSE;
}
//Sumber: Al-Farisi. 2008-2009. Membuat
Fasilitas Komentar Sederhana dengan PHP dan MySQL. www.alfarisi.web.id &
www.indokreatif.net
?>
5.
Buat
file: 7komentar_tampil.php
Ketik script berikut:
<?php
require_once '7komentar_proses.php';
session_start();
$dbconn = sql_connect('localhost', 'root', '',
'ikhbaar');
if(!$dbconn) {
$exitmsg = "Koneksi database gagal";
exit($exitmsg);
}
if (isset($_GET['id'])) {
$id =
intval($_GET['id']);
} else {
$id =
0;
}
$query = "SELECT * FROM artikel WHERE
id={$id}";
$content =
mysql_fetch_array(mysql_query($query));
echo "<div>{$content['title']}<br
/><br />";
echo "{$content['body']}</div><br
/><br />";
//
$alert = "<div><span>Silahkan
kirimkan komentar anda! </span>";
if(isset($_POST['kirim'])) {
$error
= false;
$nama
= trim($_POST['nama']);
$email
= check_email($_POST['email']);
$pesan
= trim($_POST['pesan']);
$alert
.= "<br><br><span style='color:#c00;'>";
if
(strlen($nama) < 2 || strlen($pesan) < 2) {
$alert
.= "Mohon tulis nama dengan
benar.<br>";
$error
= true;
}
if
(!$email) {
$alert
.= "Alamat e-mail anda tidak valid.<br>";
$error
= true;
}
if
(!verify_code($_POST['randomcode'], $_POST['code'])) {
$alert
.= "Kode salah.<br>";
$error
= true;
}
if
(!$error) {
$nama = strip_tags($nama);
$pesan
= strip_tags($pesan);
mysql_query("INSERT
INTO komentar (article_id, name, email, comment, date) VALUES ({$id},
'{$nama}', '{$email}', '{$pesan}', NOW() )");
unset($_POST['nama'],$_POST['email'],$_POST['pesan']);
$alert
.= "Terima kasih atas komentar anda..";
}
}
$alert .=
"</span></div><br>";
echo "<hr><a
name=''></a> <br><br>";
$query = mysql_query("SELECT * FROM
komentar WHERE article_id={$id} ORDER BY date");
while ($row = mysql_fetch_array($query)) {
$nama
= $row['name'];
$komentar
= $row['comment'];
$datestamp
= $row['date'];
echo
"<div style='border:1px solid;'>{$nama}<br
/>{$datestamp}<br />{$komentar}</div><br />";
}
$nama = isset($_POST['nama']) ? $_POST['nama']
: "";
$email = isset($_POST['email']) ?
$_POST['email'] : "";
$pesan = isset($_POST['pesan']) ?
$_POST['pesan'] : "";
echo "<a name='post'></a>
{$alert}";
$temp = create_code();
$code1 = $temp[0];
$code2 = $temp[1];
echo "<div>
<form method='POST'
action='7komentar_tampil.php?id={$id}#post'>
Nama:<br><input name='nama' size='30'
type='text' value='{$nama}'><br><br>
E-mail:<br><input name='email'
size='30' type='text' value='{$email}'><br><br>
Silahkan tulis anda :<br><textarea
cols='45' rows='5' name='pesan'>{$pesan}</textarea><br><br>
Masukkan kode berikut<br> {$code2}
<input type='hidden' id='randomcode'
name='randomcode' value='{$code1}' />
<input maxlength='6' size='6' type='text'
name='code' />
<input value=' Kirim ' name='kirim'
type='submit' />
</form>
</div>";
//Sumber: Al-Farisi. 2008-2009. Membuat
Fasilitas Komentar Sederhana dengan PHP dan MySQL. www.alfarisi.web.id &
www.indokreatif.net
?>
6.
Hasilnya:
***
Sumber:
Al-Farisi. 2008-2009. Membuat Fasilitas Komentar Sederhana dengan PHP dan MySQL.
www.alfarisi.web.id
& www.indokreatif.net
"Boleh Konsultasi Masuk Jurusan Sistem Informasi via IG atau Tiktok."
|
Tips Skripsi Program Studi Sistem Informasi |
|
No comments:
Post a Comment