Hufh setelah lama bergelut dengan semua tugas-tugas kuliah akhirnya
saya bisa menulis lagi di blog tercinta ini, yup kali ini saya akan
membuat sebuah aplikasi Login Member dengan PHP MySQL ya kira kira
nanti hasil akhirnya seperti ini :
Ok Langsung Saja kita praktekan pertama-tama kita buat terlebih dahulu file untuk penghubung ke databasenya :
config.php
03 | mysql_connect( "localhost" , "root" , "" ); |
10 | mysql_select_db( "login" ); |
nah kalo sudah kita buat penghubungnya sekarang kita buat form loginya.
login.php
05 | if (ISSET( $_SESSION [ 'username' ])){ |
06 | header( "location: index.php" ); |
09 | <style type= "text/css" > |
12 | font-family: Arial, Helvetica, sans-serif; |
17 | .style5 {color: #FFFFFF} |
18 | .style9 {color: #000000; font-weight: bold; } |
19 | .style10 {color: #000000} |
24 | <form id= "form1" name= "form1" method= "post" action= "cek.php" > |
26 | <table width= "329" border= "0" align= "center" cellpadding= "0" cellspacing= "2" > |
29 | <td height= "44" colspan= "4" bgcolor= "#999999" ><div align= "center" >CYBER LOG-IN </div></td> |
32 | <td width= "10" > </td> |
33 | <td width= "133" ><span> User Name </span></td> |
34 | <td width= "6" ><span>:<span>:</span></span></td> |
35 | <td width= "306" ><input name= "username" type= "text" /></td> |
39 | <td><span>Password</span></td> |
40 | <td><span>:<span>:</span></span></td> |
41 | <td><input name= "password" type= "password" /></td> |
47 | <td><input name= "submit" value= "Login" type= "submit" /></td> |
50 | <td height= "39" colspan= "4" bgcolor= "#999999" ><span>Bukan Member? Silahkan Daftar </span><a href= "signup.php" >Daftar</a> </td> |
cek.php
09 | $username = $_POST [ 'username' ]; |
10 | $password = $_POST [ 'password' ]; |
13 | $password_md5 = md5( $password ); |
16 | $perintah = "select * from user where username='$username'&&password='$password_md5'" ; |
17 | $perintah_di_query = mysql_query( $perintah ); |
18 | $ketersediaan = mysql_num_rows( $perintah_di_query ); |
21 | if ( $ketersediaan >= 1 ){ |
22 | $_SESSION [ 'username' ] = $username ; |
23 | header( "location: index.php" ); |
25 | header( "location: login.php" ); |
nah sekarang kita buat untuk halaman utamanya !
index.php
06 | if (ISSET( $_SESSION [ 'username' ])){ |
07 | echo "Anda Login Sebagai " ; |
08 | echo $_SESSION [ 'username' ]; |
09 | echo "<br><a href='logout.php'>logout</a>" ; |
13 | header( "location: login.php" ); |
19 | <h2>Selamat Datang di HalamanUtama !! <br> |
setelah itu kita buat pendaftaran usernya.
signup.php
01 | <style type= "text/css" > |
03 | .style1 { font-family: Arial, Helvetica, sans-serif; |
08 | .style10 {color: #000000} |
09 | .style5 {color: #FFFFFF} |
10 | .style9 {color: #000000; font-weight: bold; } |
13 | <form method= "post" action= "signup_process.php" > |
14 | <pre><h2>Form Pendaftaran</h2> |
16 | <table width= "355" border= "0" align= "center" cellpadding= "0" cellspacing= "2" > |
18 | <td height= "44" colspan= "4" bgcolor= "#999999" ><div align= "center" >REGISTRATION </div></td> |
21 | <td width= "7" > </td> |
22 | <td width= "161" ><span> Masukan User Name </span></td> |
23 | <td width= "10" ><span>:<span>:</span></span></td> |
24 | <td width= "167" ><input name= "username" type= "text" /></td> |
28 | <td><span>Masukan Password</span></td> |
29 | <td><span>:<span>:</span></span></td> |
30 | <td><input name= "password" type= "password" /></td> |
36 | <td><input name= "submit" value= "Daftar" type= "submit" /></td> |
39 | <td height= "39" colspan= "4" bgcolor= "#999999" > </td> |
signup_process
05 | $username = $_POST [ 'username' ]; |
06 | $password = $_POST [ 'password' ]; |
07 | $password_md5 = md5( $password ); |
10 | if ( $username == '' || $password == '' ){ |
11 | echo "Data tidak lengkap<br--><a href=signup.php>Back</a>" ; |
15 | $perintah = "insert into user values ('$username', '$password_md5')" ; |
16 | $perintah_di_query = mysql_query( $perintah ); |
19 | if ( $perintah_di_query ) { |
20 | echo "Daftar berhasil, silakan <a href='index.php'>login</a>" ; |
24 | echo "Daftar
gagal atau username telah terdaftar silakan <a
href='signup.php'>Ulangi</a> atau <a
href='login.php'>Login</a>" ; |
hufh alhamdulillah selesai juga ! memang dalam pembuatan Sistem Login ini harus dilakukan dengan sangat teliti.
Source : http://satyainform.wordpress.com/2012/05/09/membuat-login-member-dengan-php/