·
WampServer 2.2
·
Apache 2.2.21
·
PHP 5.3.10
·
MySQL 5.5.20
2.
Buat database: ikhbaar
Column
|
Type
|
Length
|
Extra
|
user_id
|
Integer
|
4
|
Auto_Increment
|
password
|
Varchar
|
16
|
|
username
|
Varchar
|
16
|
|
nama
|
Varchar
|
30
|
|
telp
|
Varchar
|
15
|
|
website
|
Varchar
|
75
|
|
alamat1
|
Varchar
|
50
|
|
alamat2
|
Varchar
|
50
|
|
email
|
Varchar
|
50
|
|
tanggal
|
Varchar
|
20
|
4.
Buat file: 2edit.php
Ketik script berikut:
<?php
include('2konfigurasi.php');
include('2login_cek.php');
?>
<html>
<head>
<title>Belajar PHP</title>
</head>
<body>
<h3>Ubah Profil </h3>
<?php
$id = $_GET['id'];
$query = mysql_query("select * from daftar
where user_id='$id'") or die(mysql_error());
$data = mysql_fetch_array($query);
?>
<form name="update_data"
action="2update.php" method="post">
<input type="hidden"
name="user_id" value="<?php echo $id; ?>" />
<table border="0"
cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td>Username</td>
<td>:</td>
<td><input
type="text" name="username" maxlength="20" required="required"
value="<?php echo $data['username']; ?>" disabled
/></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input
type="password" name="password" maxlength="20"
required="required" value="<?php echo $data['password'];
?>" /></td>
</tr>
<tr>
<td>Nama Lengkap </td>
<td>:</td>
<td><input
type="text" name="nama" maxlength="100"
required="required" value="<?php echo $data['nama'];
?>" /></td>
</tr>
<tr>
<td>Telp</td>
<td>:</td>
<td><input type="text"
name="telp" required="required" value="<?php echo
$data['telp']; ?>" /></td>
</tr>
<tr>
<td>Website</td>
<td>:</td>
<td><input
type="text" name="website" required="required"
value="<?php echo $data['website']; ?>" /></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><input
type="text" name="alamat1" maxlength="50"
required="required" value="<?php echo $data['alamat1'];
?>" /></td>
</tr>
<tr>
<td>Kota</td>
<td>:</td>
<td><input
type="text" name="alamat2" maxlength="50"
required="required" value="<?php echo $data['alamat2'];
?>" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text"
name="email" maxlength="50" required="required"
value="<?php echo $data['email']; ?>" />;</td>
</tr>
<tr>
<td align="right"
colspan="3"><input type="submit"
name="submit" value="Simpan" /></td>
</tr>
</tbody>
</table>
</form>
<a
href="2index1.php">Back</a>
<?php
//sumber:
http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
</body>
</html>
5.
Buat
file: 2index1.php
Ketik script berikut:
<?php
include('2konfigurasi.php');
include('2login_cek.php');
?>
<html>
<head>
<title>Belajar PHP</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<p>
<?php
echo "Selamat Datang
<strong>".$_SESSION['username']."</strong>";
?>
<br>
<br>
<a
href="2logout.php">[Logout]</a><span
class="style1">___</span>
<?php
error_reporting(E_ALL
^ (E_NOTICE | E_WARNING));
$id =
$_GET['id'];
$query
= mysql_query("select * from daftar where password='$id' ");
//$query
= mysql_query("select * from daftar");
$data
= mysql_fetch_array($query);
?>
<td>
<a
href="2tampil.php?password=<?php echo
"".$_SESSION['password'].""; ?>">[Profil
Lengkap]</a>
</td>
</tr>
<?php
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
</body>
</html>
6.
Buat file: 2konfigurasi.php
Ketik script berikut:
<?php
//host yang digunakan
//99,9% tidak perlu dirubah
$host = 'localhost';
//username untuk login ke host
//biasanya didapatkan pada email konfirmasi order hosting
$user = 'root';
//jika menggunakan PC sendiri sebagai host,
//secara default password dikosongkan
$pass = '';
//isikan nama database sesuai database
//yang dibuat pada langkah-1
$dbname = 'ikhbaar';
//mengubung ke host
$connect = mysql_connect($host, $user, $pass) or die(mysql_error());
//memilih database yang akan digunakan
$dbselect = mysql_select_db($dbname);
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
7.
Buat file: 2login.php
Ketik script berikut:
<?php
session_start();
if (!empty($_SESSION['username'])) {
header('location:2index1.php');
}
?>
<html>
<head>
<title>LOGIN</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
LOGIN <span class="style1">aaaa</span>||<span
class="style1">aaa</span><a href="">Daftar
(Tidak diaktifkan)</a>
<?php
//kode php ini kita gunakan untuk menampilkan pesan eror
if (!empty($_GET['error'])) {
if ($_GET['error'] == 1) {
echo
'<h3>Username dan Password belum diisi!</h3>';
} else if ($_GET['error'] ==
2) {
echo
'<h3>Username belum diisi!</h3>';
} else if ($_GET['error'] ==
3) {
echo
'<h3>Password belum diisi!</h3>';
} else if ($_GET['error'] ==
4) {
echo
'<h3>Username dan Password tidak terdaftar!</h3>';
}
}
?>
<form name="login" action="2otentikasi.php"
method="post">
<table width="162" border="1">
<tr>
<td
width="152"><table border="0"
cellpadding="5" cellspacing="0">
<tr>
<td>Username:</td>
</tr>
<tr>
<td><input
type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
</tr>
<tr>
<td><input
type="password" name="password" /></td>
</tr>
<tr
align="right">
<td
colspan="3"><input type="submit"
name="login" value="Login" /></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
</form>
</body>
<?php
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
</html>
8.
Buat file: 2login_cek.php
Ketik script berikut:
<?php
session_start();
//jika session username belum dibuat, atau session username kosong
if (!isset($_SESSION['username']) || empty($_SESSION['username'])) {
//redirect ke halaman login
header('location:2login.php');
}
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
9.
Buat file: 2logout.php
Ketik script berikut:
<?php
//lanjutkan session yang sudah dibuat sebelumnya
session_start();
//hapus session yang sudah dibuat
session_destroy();
//redirect ke halaman login
header('location:2login.php');
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
10.
Buat file: 2otentikasi.php
Ketik script berikut:
<?php
include('2konfigurasi.php');
session_start();
//tangkap data dari form login
$username = $_POST['username'];
$password = $_POST['password'];
//untuk mencegah sql injection
//kita gunakan mysql_real_escape_string
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
//cek data yang dikirim, apakah kosong atau tidak
if (empty($username) && empty($password)) {
//kalau username dan password
kosong
header('location:2login.php?error=1');
break;
} else if (empty($username)) {
//kalau username saja yang
kosong
header('location:2login.php?error=2');
break;
} else if (empty($password)) {
//kalau password saja yang
kosong
header('location:2login.php?error=3');
break;
}
$q = mysql_query("select * from daftar where username='$username'
and password='$password'");
if (mysql_num_rows($q) == 1) {
//kalau username dan password
sudah terdaftar di database
//buat session dengan nama
username dengan isi nama user yang login
$_SESSION['username'] =
$username;
$_SESSION['password'] =
$password;
//redirect ke halaman index
header('location:2index1.php');
} else {
//kalau username ataupun
password tidak terdaftar di database
header('location:2login.php?error=4');
}
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
11.
Buat file: 2pesan_update.php
Ketik script berikut:
<?php
if (!empty($_GET['message']) && $_GET['message'] == 'success') {
echo '<h3>Berhasil
meng-update data!</h3>';
}
?>
<?php
include('2konfigurasi.php');
include('2login_cek.php');
?>
<html>
<head>
<title>Belajar PHP</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<br>
<a
href="2logout.php">[Logout]</a><span
class="style1">___</span>
<?php
error_reporting(E_ALL ^
(E_NOTICE | E_WARNING));
$id = $_GET['id'];
$query =
mysql_query("select * from daftar where password='$id' ");
//$query =
mysql_query("select * from daftar");
$data =
mysql_fetch_array($query);
?>
<td>
<a
href="2tampil.php?password=<?php echo
"".$_SESSION['password'].""; ?>">[Lihat
Perubahan Profil]</a>
</td>
</tr>
<?php
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
</body>
</html>
12.
Buat file: 2tampil.php
Ketik script berikut:
<?php
include('2konfigurasi.php');
include('2login_cek.php');
?>
<html>
<head>
<title>Belajar PHP</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<h1>Data User</h1>
<?php
if (!empty($_GET['message']) && $_GET['message'] == 'success') {
echo '<h3>Berhasil
meng-update data!</h3>';
}
?>
<table border="1" cellpadding="5"
cellspacing="0">
<thead>
<tr>
<td>Username</td>
<td>Password</td>
<td>Nama Lengkap</td>
<td>Telepon</td>
<td>Website</td>
<td>Alamat1</td>
<td>Alamat2</td>
<td>Email</td>
</tr>
</thead>
<tbody>
<?php
$id = $_GET['password'];
$query =
mysql_query("select * from daftar where password='$id' ");
$data =
mysql_fetch_array($query);
?>
<tr>
<td><?php echo $data['username']; ?></td>
<td><?php echo $data['password']; ?></td>
<td><?php echo $data['nama']; ?></td>
<td><?php echo $data['telp']; ?></td>
<td><?php echo $data['website']; ?></td>
<td><?php echo $data['alamat1']; ?></td>
<td><?php
echo $data['alamat2']; ?></td>
<td><?php
echo $data['email']; ?></td>
</tr>
</tbody>
</table>
<br>
<br>
<a href="2index1.php">Back</a><span
class="style1">___</span>
<a href="2edit.php?id=<?php echo $data['user_id'];
?>">Edit</a>
</body>
<?php
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
</html>
13.
Buat file: 2update.php
Ketik script berikut:
<?php
include('2konfigurasi.php');
//tangkap data dari form
$id = $_POST['user_id'];
$password = $_POST['password'];
//$username = $_POST['username'];
$nama = $_POST['nama'];
$telp = $_POST['telp'];
$website = $_POST['website'];
$alamat1 = $_POST['alamat1'];
$alamat2 = $_POST['alamat2'];
$email = $_POST['email'];
$tanggal = $_POST['tanggal'];
//update data di database sesuai user_id
$query = mysql_query("update daftar set user_id='$id',
password='$password', nama='$nama', telp='$telp', website='$website',
alamat1='$alamat1', alamat2='$alamat2', email='$email', tanggal='$tanggal'
where user_id='$id'") or die(mysql_error());
if ($query) {
header('location:2pesan_update.php?message=success');
}
//sumber: http://www.nurwahyudin.com/php/membuat-sistem-login-dengan-php
?>
14.
Halaman depan login seperti berikut (ada pada
file 2login.php):
***
Sumber: nurwahyudin.com/php/membuat-sistem-login-dengan-php
"Boleh Konsultasi Masuk Jurusan Sistem Informasi via IG atau Tiktok."
|
Tips Skripsi Program Studi Sistem Informasi |
|
No comments:
Post a Comment