SHARE
TWEET

login.php

a guest Mar 20th, 2016 178 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start(); // Memulai Session
  3. $error=''; // Variabel untuk menyimpan pesan error
  4. if (isset($_POST['submit'])) {
  5.     if (empty($_POST['username']) || empty($_POST['password'])) {
  6.             $error = "Username or Password is invalid";
  7.     }
  8.     else
  9.     {
  10.         // Variabel username dan password
  11.         $username=$_POST['username'];
  12.         $password=$_POST['password'];
  13.         // Membangun koneksi ke database
  14.         $connection = mysql_connect("localhost", "root","");
  15.         // Mencegah mysql injection
  16.         $username = stripslashes($username);
  17.         $password = stripslashes($password);
  18.         $username = mysql_real_escape_string($username);
  19.         $password = mysql_real_escape_string($password);
  20.         // Seleksi Database
  21.         $db = mysql_select_db("db_login", $connection);
  22.         // SQL query untuk memeriksa apakah karyawan terdapat di database?
  23.         $query = mysql_query("select * from t_admin where pass_admin='$password' AND user_admin='$username'", $connection);
  24.         $rows = mysql_num_rows($query);
  25.             if ($rows == 1) {
  26.                 $_SESSION['login_user']=$username; // Membuat Sesi/session
  27.                 header("location: profile.php"); // Mengarahkan ke halaman profil
  28.                 } else {
  29.                 $error = "Username atau Password belum terdaftar";
  30.                 }
  31.                 mysql_close($connection); // Menutup koneksi
  32.     }
  33. }
  34. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top