Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>index.php</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- </head>
- <body>
- <br/>
- <br/>
- <center><h2>bayu elsya</h2></center>
- <br/>
- <div class="login">
- <br/>
- <form action="login.php" method="post" onSubmit="return validasi()">
- <div>
- <label>Username:</label>
- <input type="text" name="username" id="username" />
- </div>
- <div>
- <label>Password:</label>
- <input type="password" name="password" id="password" />
- </div>
- <div>
- <input type="submit" value="Login" class="tombol">
- </div>
- </form>
- </div>
- </body>
- <script type="text/javascript">
- function validasi() {
- var username = document.getElementById("username").value;
- var password = document.getElementById("password").value;
- if (username != "" && password!="") {
- return true;
- }else{
- alert('Username dan Password harus di isi !');
- return false;
- }
- }
- </script>
- </html>
- ====
- Login.php
- <?php
- include 'config.php';
- $username = $_POST['username'];
- $password = md5($_POST['password']);
- $login = mysql_query("select * from user where username='$username' and password='$password'");
- $cek = mysql_num_rows($login);
- if($cek > 0){
- session_start();
- $_SESSION['username'] = $username;
- $_SESSION['status'] = "login";
- header("location:admin/index.php");
- }else{
- header("location:index.php");
- }
- ?>
- ======
- Conffig.php
- <?php
- mysql_connect('localhost','root','');
- mysql_select_db('admin');
- ?>
- =====
- /Admin/index.php
- <?php
- include '../config.php';
- // mengaktifkan session
- session_start();
- // cek apakah user telah login, jika belum login maka di alihkan ke halaman login
- if($_SESSION['status'] !="login"){
- header("location:../index.php");
- }
- // menampilkan pesan selamat datang
- echo "Hai, selamat datang ". $_SESSION['username'];
- ?>
- <br/>
- <br/>
- <a href="logout.php">LOGOUT</a>
- =====
- Logout.php
- <?php
- session_start();
- session_destroy();
- header("location:../index.php");
- ?>
- =====
- Tabel
- CREATE TABLE `user` (
- `id` int(11) NOT NULL,
- `nama` varchar(225) NOT NULL,
- `username` varchar(225) NOT NULL,
- `password` varchar(225) NOT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement