daily pastebin goal
7%
SHARE
TWEET

coeg

a guest Dec 29th, 2016 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. include('config/koneksi.php');
  3.  
  4. session_start();
  5.  
  6. //tangkap data dari form login
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9.  
  10. //untuk mencegah sql injection
  11. //kita gunakan mysql_real_escape_string
  12. $username = mysql_real_escape_string($username);
  13. $password = mysql_real_escape_string($password);
  14.  
  15. //cek data yang dikirim, apakah kosong atau tidak
  16. if (empty($username) && empty($password)) {
  17.     //kalau username dan password kosong
  18.     header('location:login.php?error=1');
  19.     break;
  20. } else if (empty($username)) {
  21.     //kalau username saja yang kosong
  22.     header('location:login.php?error=2');
  23.     break;
  24. } else if (empty($password)) {
  25.     //kalau password saja yang kosong
  26.     header('location:login.php?error=3');
  27.     break;
  28. }
  29.  
  30. $q = mysql_query("select * from user where username_user='$username' and password_user='$password'");
  31.  
  32. if (mysql_num_rows($q) == 1) {
  33.     //kalau username dan password sudah terdaftar di database
  34.     //buat session dengan nama username dengan isi nama user yang login
  35.     $_SESSION['username'] = $username;
  36.      
  37.     //redirect ke halaman index
  38.     header('location:index.php');
  39. } else {
  40.     //kalau username ataupun password tidak terdaftar di database
  41.     header('location:login.php?error=4');
  42. }
  43. ?>
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