Download
| demo
pertama - tama kita jalankan dulu XAMPP nya.
kemudian buat script untuk form login nya ? contoh scriptnya dibawah ini.
buat lah data basesnya terlebih dahulu . di home adress buka alamat berikut http://localhost/phpmyadmin/
kemudian buat data bases dengan nama sigit septianto
kemudian klik create untuk membuat table tersebut.
buat lah data basesnya terlebih dahulu . di home adress buka alamat berikut http://localhost/phpmyadmin/
kemudian buat data bases dengan nama sigit septianto
kemudian klik create untuk membuat table tersebut.
selanjutnya cari nama sigit septianto untuk membuat element didalam sigit septianto. contohnya seperti gambar berikut.
selanjutnya buat element tersebut dengan nama sigit dan jumlah tablenya 4. contohnya sepeti gambar berikut ini.
next ? isi dari tabel sigit tersebut ada 4. yaitu:
nama varchar 225
alamat varchar 225
phone varchar 225
password varchar 225
dan kemudian klik save untuk menyimpanya. contohnya seperti gambar berikut
lakukanlah
pendaftaran terlebih dahulu sebelum login . maka akan tersimpan di
databases yg sudah kita buat. contohnya seperti gambar berikut.
pembuatan databases sudah selesai. tinggal pembuatan formnya .
<style type="text/css">
body {
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.registration_form {
margin:0 auto;
width:500px;
padding:14px;
}
label {
width: 10em;
float: left;
margin-right: 0.5em;
display: block
}
.submit {
float:right;
}
fieldset {
background:#EBF4FB none repeat scroll 0 0;
border:2px solid #B7DDF2;
width: 500px;
}
legend {
color: #fff;
background: #80D3E2;
border: 1px solid #781351;
padding: 2px 6px
}
.elements {
padding:10px;
}
p {
border-bottom:1px solid #B7DDF2;
color:#666666;
font-size:11px;
margin-bottom:20px;
padding-bottom:10px;
}
a{
color:#0099FF;
font-weight:bold;
}
a:hover{
color:#0066FF;
text-decoration:none;
}
/* Box Style */
.success, .warning, .errormsgbox, .validation {
border: 1px solid;
margin: 0 auto;
padding:10px 5px 10px 60px;
background-repeat: no-repeat;
background-position: 10px center;
font-weight:bold;
width:450px;
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}
.warning {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}
.errormsgbox {
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('images/error.png');
}
</style>
<center>
<?
echo "
<form method='post' action='cek_login.php' class='registration_form'>
<fieldset>
<legend>Form Login </legend>
<table> <tr><td colspan='2'> <b>HALAMAN LOG IN </b></td><tr>
<tr><td> Nama </td><td><input type='text' name='input_nama'></td></tr>
<tr><td> Password </td><td><input type='password' name='input_password'></td></tr>
</table>
<input type='submit' name='login' value='Log in..'>
</form>
<a href='form_daftar.php'>Daftar ?</a><br>
<br><font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font>";
?>
</center>
body {
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.registration_form {
margin:0 auto;
width:500px;
padding:14px;
}
label {
width: 10em;
float: left;
margin-right: 0.5em;
display: block
}
.submit {
float:right;
}
fieldset {
background:#EBF4FB none repeat scroll 0 0;
border:2px solid #B7DDF2;
width: 500px;
}
legend {
color: #fff;
background: #80D3E2;
border: 1px solid #781351;
padding: 2px 6px
}
.elements {
padding:10px;
}
p {
border-bottom:1px solid #B7DDF2;
color:#666666;
font-size:11px;
margin-bottom:20px;
padding-bottom:10px;
}
a{
color:#0099FF;
font-weight:bold;
}
a:hover{
color:#0066FF;
text-decoration:none;
}
/* Box Style */
.success, .warning, .errormsgbox, .validation {
border: 1px solid;
margin: 0 auto;
padding:10px 5px 10px 60px;
background-repeat: no-repeat;
background-position: 10px center;
font-weight:bold;
width:450px;
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}
.warning {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}
.errormsgbox {
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('images/error.png');
}
</style>
<center>
<?
echo "
<form method='post' action='cek_login.php' class='registration_form'>
<fieldset>
<legend>Form Login </legend>
<table> <tr><td colspan='2'> <b>HALAMAN LOG IN </b></td><tr>
<tr><td> Nama </td><td><input type='text' name='input_nama'></td></tr>
<tr><td> Password </td><td><input type='password' name='input_password'></td></tr>
</table>
<input type='submit' name='login' value='Log in..'>
</form>
<a href='form_daftar.php'>Daftar ?</a><br>
<br><font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font>";
?>
</center>
Selanjutnya kita buat lagi untuk melakukan pendaftaran terlebih dahulu .
scriptnya seperti dibawah ini.
<style type="text/css">
body {
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.registration_form {
margin:0 auto;
width:500px;
padding:14px;
}
label {
width: 10em;
float: left;
margin-right: 0.5em;
display: block
}
.submit {
float:right;
}
fieldset {
background:#EBF4FB none repeat scroll 0 0;
border:2px solid #B7DDF2;
width: 500px;
}
legend {
color: #fff;
background: #80D3E2;
border: 1px solid #781351;
padding: 2px 6px
}
.elements {
padding:10px;
}
p {
border-bottom:1px solid #B7DDF2;
color:#666666;
font-size:11px;
margin-bottom:20px;
padding-bottom:10px;
}
a{
color:#0099FF;
font-weight:bold;
}
a:hover{
color:#0066FF;
text-decoration:none;
}
/* Box Style */
.success, .warning, .errormsgbox, .validation {
border: 1px solid;
margin: 0 auto;
padding:10px 5px 10px 60px;
background-repeat: no-repeat;
background-position: 10px center;
font-weight:bold;
width:450px;
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}
.warning {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}
.errormsgbox {
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('images/error.png');
}
</style>
<?
echo "
<center>
<fieldset>
<legend>Form Daftar / Registrasi </legend>
<form method='post' action='daftar.php'>
<table> <tr><td colspan='2'> <b>HALAMAN DAFTAR </b></td><tr>
<tr><td> Nama </td><td><input type='text' name='daftar_nama'></td></tr>
<tr><td> Alamat </td><td><input type='text' name='daftar_alamat'></td></tr>
<tr><td> Phone </td><td><input type='text' name='daftar_phone'></td></tr>
<tr><td> Password </td><td><input type='password' name='daftar_password'></td></tr>
</table>
<input type='submit' value='Daftar..'> <input type='reset' value='Batal'>
</form>
<a href='form_login.php'>Log in </a><br>
<br><font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font></center>";
?>
body {
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.registration_form {
margin:0 auto;
width:500px;
padding:14px;
}
label {
width: 10em;
float: left;
margin-right: 0.5em;
display: block
}
.submit {
float:right;
}
fieldset {
background:#EBF4FB none repeat scroll 0 0;
border:2px solid #B7DDF2;
width: 500px;
}
legend {
color: #fff;
background: #80D3E2;
border: 1px solid #781351;
padding: 2px 6px
}
.elements {
padding:10px;
}
p {
border-bottom:1px solid #B7DDF2;
color:#666666;
font-size:11px;
margin-bottom:20px;
padding-bottom:10px;
}
a{
color:#0099FF;
font-weight:bold;
}
a:hover{
color:#0066FF;
text-decoration:none;
}
/* Box Style */
.success, .warning, .errormsgbox, .validation {
border: 1px solid;
margin: 0 auto;
padding:10px 5px 10px 60px;
background-repeat: no-repeat;
background-position: 10px center;
font-weight:bold;
width:450px;
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}
.warning {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}
.errormsgbox {
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('images/error.png');
}
</style>
<?
echo "
<center>
<fieldset>
<legend>Form Daftar / Registrasi </legend>
<form method='post' action='daftar.php'>
<table> <tr><td colspan='2'> <b>HALAMAN DAFTAR </b></td><tr>
<tr><td> Nama </td><td><input type='text' name='daftar_nama'></td></tr>
<tr><td> Alamat </td><td><input type='text' name='daftar_alamat'></td></tr>
<tr><td> Phone </td><td><input type='text' name='daftar_phone'></td></tr>
<tr><td> Password </td><td><input type='password' name='daftar_password'></td></tr>
</table>
<input type='submit' value='Daftar..'> <input type='reset' value='Batal'>
</form>
<a href='form_login.php'>Log in </a><br>
<br><font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font></center>";
?>
selanjutnya kita buat perintah untuk melaukan penyimpanan ke databases
scriptnya seperti berikut
beri nama daftar.php
<?
$host="localhost";
$user="root";
$password="";
$db="sigit septianto";
$konek=mysql_connect($host,$user,$password) or die (mysql_error());
mysql_select_db($db,$konek) or die (mysql_error());
mysql_query("insert into sigit values('$_POST[daftar_nama]','$_POST[daftar_alamat]','$_POST[daftar_phone]','$_POST[daftar_password]')",$konek) or die(mysql_error());
echo "
<center>
<fieldset>
<legend>berhasil </legend>
Pendaftaran berhasil...<br>
Silakan login...<br><br>
<br><font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font></center>";
header("refresh:1;url='form_login.php' ");
?>
$host="localhost";
$user="root";
$password="";
$db="sigit septianto";
$konek=mysql_connect($host,$user,$password) or die (mysql_error());
mysql_select_db($db,$konek) or die (mysql_error());
mysql_query("insert into sigit values('$_POST[daftar_nama]','$_POST[daftar_alamat]','$_POST[daftar_phone]','$_POST[daftar_password]')",$konek) or die(mysql_error());
echo "
<center>
<fieldset>
<legend>berhasil </legend>
Pendaftaran berhasil...<br>
Silakan login...<br><br>
<br><font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font></center>";
header("refresh:1;url='form_login.php' ");
?>
Selanjutnya bikin koneksi ke databases.
berikut scriptnya.
beri nama koneksi.php
<?php
$host ="localhost";
$username ="root";
$password ="";
$database ="amcc";
mysql_conect($host, $username, $password)or die ("tidak Koneksi");
mysql_select_db($database)or die ("tidak ada database");
?>
$host ="localhost";
$username ="root";
$password ="";
$database ="amcc";
mysql_conect($host, $username, $password)or die ("tidak Koneksi");
mysql_select_db($database)or die ("tidak ada database");
?>
selanjutnya buat cek login.? jika pendaftaran berhasil maka bisa login. jika tidak maka gagal login.
berikut scriptnya
beri nama cek_login.php
<style type="text/css">
body {
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.registration_form {
margin:0 auto;
width:500px;
padding:14px;
}
label {
width: 10em;
float: left;
margin-right: 0.5em;
display: block
}
.submit {
float:right;
}
fieldset {
background:#EBF4FB none repeat scroll 0 0;
border:2px solid #B7DDF2;
width: 500px;
}
legend {
color: #fff;
background: #80D3E2;
border: 1px solid #781351;
padding: 2px 6px
}
.elements {
padding:10px;
}
p {
border-bottom:1px solid #B7DDF2;
color:#666666;
font-size:11px;
margin-bottom:20px;
padding-bottom:10px;
}
a{
color:#0099FF;
font-weight:bold;
}
a:hover{
color:#0066FF;
text-decoration:none;
}
/* Box Style */
.success, .warning, .errormsgbox, .validation {
border: 1px solid;
margin: 0 auto;
padding:10px 5px 10px 60px;
background-repeat: no-repeat;
background-position: 10px center;
font-weight:bold;
width:450px;
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}
.warning {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}
.errormsgbox {
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('images/error.png');
}
</style>
<?
$host="localhost";
$user="root";
$password="";
$db="sigit septianto";
$konek=mysql_connect($host,$user,$password) or die (mysql_error());
mysql_select_db($db,$konek) or die (mysql_error());
$nama_login=$_POST['input_nama'];
$password_login=$_POST['input_password'];
$query_login=mysql_query("select * from sigit where nama='$nama_login' and password='$password_login'",$konek);
$baris=mysql_num_rows($query_login);
if ($baris==1)
{
session_register("input_nama");
session_register ("input_password");
$_SESSION['nama']=$nama_login;
header ("location:login_sukses.php");
}
else
{
echo "<center><fieldset>
<legend>Error </legend>
<font size='4'>Username atau password salah ...!</font><br><br>
<a href='form_login.php'>Log in </a><br>
<br>
<font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font></center>";
}
ob_end_flush();
?>
body {
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.registration_form {
margin:0 auto;
width:500px;
padding:14px;
}
label {
width: 10em;
float: left;
margin-right: 0.5em;
display: block
}
.submit {
float:right;
}
fieldset {
background:#EBF4FB none repeat scroll 0 0;
border:2px solid #B7DDF2;
width: 500px;
}
legend {
color: #fff;
background: #80D3E2;
border: 1px solid #781351;
padding: 2px 6px
}
.elements {
padding:10px;
}
p {
border-bottom:1px solid #B7DDF2;
color:#666666;
font-size:11px;
margin-bottom:20px;
padding-bottom:10px;
}
a{
color:#0099FF;
font-weight:bold;
}
a:hover{
color:#0066FF;
text-decoration:none;
}
/* Box Style */
.success, .warning, .errormsgbox, .validation {
border: 1px solid;
margin: 0 auto;
padding:10px 5px 10px 60px;
background-repeat: no-repeat;
background-position: 10px center;
font-weight:bold;
width:450px;
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}
.warning {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}
.errormsgbox {
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('images/error.png');
}
</style>
<?
$host="localhost";
$user="root";
$password="";
$db="sigit septianto";
$konek=mysql_connect($host,$user,$password) or die (mysql_error());
mysql_select_db($db,$konek) or die (mysql_error());
$nama_login=$_POST['input_nama'];
$password_login=$_POST['input_password'];
$query_login=mysql_query("select * from sigit where nama='$nama_login' and password='$password_login'",$konek);
$baris=mysql_num_rows($query_login);
if ($baris==1)
{
session_register("input_nama");
session_register ("input_password");
$_SESSION['nama']=$nama_login;
header ("location:login_sukses.php");
}
else
{
echo "<center><fieldset>
<legend>Error </legend>
<font size='4'>Username atau password salah ...!</font><br><br>
<a href='form_login.php'>Log in </a><br>
<br>
<font color='red'> Sigit Septianto | sigit04091993@gmail.com<br>
Mahasiswa STMIK AMIKOM YOGYAKARTA</font></center>";
}
ob_end_flush();
?>
selanjutnya kita buat login berhasilnya.. jika udah masuk / berhasil login.
berikut sciptnya
beri nama login_sukses.php
<?
session_start();
if (!$_SESSION['nama'])
{
header ("location:form.php");
}
else
header ("location: ");
echo "
<font color='#8A2BE2'><b>
KAMU TELAH BERHASIL LOG IN <br></font>
<a href='logout.php'><b>LOG OUT</b></a>
";
?>
Selanjutnya buat logoutnya untuk keluar.
berikut scriptnya.
beri nama logout.php
<?
session_start();
if (!$_SESSION['nama'])
{
header ("location:form_daftar.php");
}
else
{
unset($_SESSION);
session_destroy();
header ("location:form_login.php");
}
?>
session_start();
if (!$_SESSION['nama'])
{
header ("location:form_daftar.php");
}
else
{
unset($_SESSION);
session_destroy();
header ("location:form_login.php");
}
?>
0 Comments for "membuat login , logout dengan php"