- buat database
- buat tabel
|  | CREATE TABLE `admin` ( | 
|  | `admin_id` INT(11) NOT NULL AUTO_INCREMENT, | 
|  | `admin_username` VARCHAR(40) DEFAULT NULL, | 
|  | `admin_password` VARCHAR(225) DEFAULT NULL, | 
|  | PRIMARY KEY (`admin_id`) | 
|  | ) ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 | 
 
 
 
 
 
 
- buat file inc-db.php
|  | <?php | 
|  | mysql_connect('localhost','root',''); | 
|  | mysql_select_db('phpnet'); | 
|  | ?> | 
 
 
 
 
 
 
- buat file login.php
|  | <form method="post" action="login_check.php"> | 
|  | Username : <input type="text" name="username"><br> | 
|  | password : <input type="text" name="password"><br> | 
|  | <input type="submit" name="login" value="login"> | 
|  | </form> | 
 
 
 
 
 
 
- buat file login_check.php
|  | <?php | 
|  | include('inc-db.php'); | 
|  | $username=$_POST['username']; | 
|  | $password=$_POST['password']; | 
|  |  | 
|  | $sql_check="select * from admin where | 
|  | admin_username='".$username."'"; | 
|  |  | 
|  | $result = mysql_query($sql_check); | 
|  |  | 
|  | $getUser = mysql_num_rows($result); | 
|  |  | 
|  | //print_r($getUser); die(); | 
|  | $getDataUser = mysql_fetch_array($result); | 
|  | if ($getUser === 1) | 
|  | { | 
|  |  | 
|  |  | 
|  | if (password_verify($password,$getDataUser['admin_password'])) | 
|  | { | 
|  | session_start(); | 
|  | $_SESSION['username']=$getDataUser['admin_username']; | 
|  | header('location: admin_area.php'); | 
|  | //echo "Is Valid User"; | 
|  | } | 
|  | else | 
|  | { | 
|  | echo "Invalid User"; | 
|  | } | 
|  |  | 
|  |  | 
|  | } | 
|  | else | 
|  | { | 
|  | echo "Invalid User"; | 
|  | } | 
|  |  | 
|  |  | 
|  |  | 
|  | ?> | 
 
 
 
 
 
 
- buat file admin_area.php
|  | <?php | 
|  | session_start(); | 
|  | if(!empty($_SESSION['username'])) | 
|  | { | 
|  | ?> | 
|  | <h1>Halaman Admin</h1> | 
|  | <a href="logout.php">Logout</a> | 
|  | <?php | 
|  | }else{ | 
|  | header('location: login.php'); | 
|  | } | 
|  | ?> | 
 
 
 
 
 
 
- buat file logout.php
|  | <?php | 
|  | session_start(); | 
|  | session_destroy(); | 
|  | header('location: login.php'); | 
|  | ?> | 
 
 
 
 
 
 
untuk download source code 
disini 
 
0 Response to "coding php"
Posting Komentar