Advertisement
kura2yamato

perbaikan 11

Oct 24th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <!--- ============CONFIG========== -->
  2.  <?php
  3.  
  4. define('DBHOST', 'localhost');
  5. define('DBUSER', 'root');
  6. define('DBPASS', '');
  7. define('DBNAME', 'mdcweb');
  8.  
  9. /**
  10. * $dbconnect : koneksi kedatabase
  11. */
  12. $dbconnect = new mysqli(DBHOST,DBUSER,DBPASS,DBNAME);
  13.  
  14. /**
  15. * check error yang terjadi saat koneksi
  16. * jika terdapat error maka die() // stop dan tampilkan error
  17. */
  18. if ($dbconnect->connect_error) {
  19. die('Database Not Connect. Error : ' . $dbconnect->connect_error);
  20. }
  21.  
  22. <!-- code-->
  23.  <?php
  24. session_start();
  25. require 'config.php';
  26.  
  27. if ( isset($_POST['username']) && isset($_POST['password']) ) {
  28.  
  29. $sql_check = "SELECT nama,
  30. level_user,
  31. id_user
  32. FROM users
  33. WHERE
  34. username=?
  35. AND
  36. password=?
  37. LIMIT 1";
  38.  
  39. $check_log = $dbconnect->prepare($sql_check);
  40. //$check_log->bind_param('ss', $username, $password);
  41. //base dari https://stackoverflow.com/questions/15748254/how-to-run-the-bind-param-statement-in-php
  42.  
  43. $username = $_POST['username'];
  44. $password = md5($_POST["password"] );
  45. $check_log->bind_param('ss', $username, $password);
  46. if($check_log->execute()){
  47. //==================
  48. $check_log->store_result();
  49.  
  50. if ( $check_log->num_rows == 1) {
  51. $check_log->bind_result($nama, $level_user, $id_user);
  52.  
  53. while ( $check_log->fetch() ) {
  54. $_SESSION['user_login'] = $level_user;
  55. $_SESSION['sess_id'] = $id_user;
  56. $_SESSION['nama'] = $nama;
  57.  
  58. }
  59.  
  60. $check_log->close();
  61. //===========================
  62. }
  63. else{
  64. die('error!!');
  65. }
  66.  
  67.  
  68.  
  69. header('location:on-' .$level1_user);
  70. exit();
  71.  
  72. } else {
  73. header('location: login.php?error=' .base64_encode('Username dan Password Invalid!!!'));
  74. exit();
  75. }
  76.  
  77. } else {
  78. header('location:login.php');
  79. exit();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement