HamdanNur

otentikasi

Jan 4th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include('koneksi.php');
  4.  
  5. //tangkap data dari form login
  6.  
  7. $id_daftar = $_POST['id_daftar'];
  8. $email = $_POST['email'];
  9. $password = $_POST['password'];
  10.  
  11. //untuk mencegah sql injection
  12. //kita gunakan mysql_real_escape_string
  13. $email = mysql_real_escape_string($email);
  14. $password = mysql_real_escape_string($password);
  15. //cek data yang dikirim, apakah kosong atau tidak
  16. if (empty($email) && empty($password)) {
  17. //kalau email dan password kosong
  18. header('location:index.php?hal=login&error=1');
  19. break;
  20. } else if (empty($email)) {
  21. //kalau email saja yang kosong
  22. header('location:index.php?hal=login&error=2');
  23. break;
  24. } else if (empty($password)) {
  25. //kalau password saja yang kosong
  26. header('location:index.php?hal=login&error=3');
  27. break;
  28. }
  29.  
  30. $q = mysql_query("select * from daftar where email='$email' and password='$password'");
  31. $data_siswa = mysql_fetch_array($q);
  32. $cek_siswa = mysql_num_rows($q);
  33.  
  34. if (mysql_num_rows($q) == 1) {
  35. //kalau email dan password sudah terdaftar di database
  36. //buat session dengan nama email dengan isi nama user yang login
  37.  
  38. $_SESSION['email'] = $email;
  39. $_SESSION['password'] = $password;
  40. //redirect ke halaman index
  41.  
  42. header("location:index.php?hal=lihat_data");
  43.  
  44.  
  45. } else {
  46. //kalau email ataupun password tidak terdaftar di database
  47. header('location:index.php?hal=login&error=4');
  48. }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment