Hallo! Selamat Datang di Marketplace produk digital, Freelancer terbaik di indonesia (68414 Members, 793 Products, 5353 Topic, 13045 Comments)

login multi user gk jalan...

Dibuat
Login Terakhir 17 Hari lalu,
Telah Dilihat 1321 Kali
Rafisqy Adhideva Mengatakan : Sultan Account
  1. Assalamualaikum Warahmatullahi Wabarakatuh...
  2.  
  3. Mastah2 yg sy hormati, sy ada kesulitan ttg form login multi user dimana mksd sy adalah tiap user ada role sendiri...jd saat login username dan password otomatis di redirect ke dashboard masing2...nah sy udah bikin form login dan user otentikasi tp kok tidak berjalan ya master...mohon pencerahannya...terima kasih...
  4.  
  5. Wassalam....
  6.  
  7.  
  8. Form login :
  9.  
  10. <?php $pagedesc = "Login"; ?>
  11. <!DOCTYPE html>
  12. <html lang="en">
  13. <head>
  14. <meta charset="utf-8">
  15. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  16. <meta name="viewport" content="width=device-width, initial-scale=1">
  17. <meta name="description" content="">
  18. <meta name="author" content="">
  19.  
  20. <title>e - Cuti <?php echo $pagedesc ?></title>
  21.  
  22. <link href="libs/images/#" rel="icon" type="images/x-icon">
  23.  
  24. <!-- Bootstrap Core CSS -->
  25. <link href="libs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
  26.  
  27. <!-- Custom CSS -->
  28. <link href="dist/css/offline-font.css" rel="stylesheet">
  29. <link href="dist/css/custom.css" rel="stylesheet">
  30.  
  31. <!-- Custom Fonts -->
  32. <link href="libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
  33.  
  34. <!-- jQuery -->
  35. <script src="libs/jquery/dist/jquery.min.js"></script>
  36.  
  37. <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  38. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  39. <!--[if lt IE 9]>
  40. <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  41. <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  42. <![endif]-->
  43. </head>
  44.  
  45. <body style="background-color: #f1f4f7">
  46.  
  47. <section id="main-wrapper" style="margin-top: 120px">
  48. <div class="container-fluid">
  49. <div class="row">
  50. <div class="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4"><?php include("layout_alert.php"); ?></div>
  51. </div><!-- /.row -->
  52. <div class="row">
  53. <div id="page-wrapper" class="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4" style="background-color: #ffffff; border-radius: 3px; webkit-box-shadow: 0 1px 1px rgba(0,0,0,.05); box-shadow: 0 1px 1px rgba(0,0,0,.05)">
  54. <div class="row">
  55. <div class="col-lg-12">
  56. <br/>
  57. <center><img src="libs/images/#" width="145" height="120"></center>
  58. <h2 class="text-center">e - Cuti<br/> <b>#</b></h2>
  59. </div>
  60. </div><!-- /.row -->
  61. <div class="row">
  62. <div class="col-lg-12">
  63. <div class="panel panel-default">
  64. <div class="panel-body">
  65. <form action="login_auth.php" method="post">
  66. <div class="form-group">
  67. <input type="text" class="form-control" name="username" placeholder="Username" required>
  68. </div>
  69. <div class="form-group">
  70. <input type="password" class="form-control" name="password" placeholder="Password" required>
  71. </div>
  72. <div class="form-group">
  73. <input type="submit" class="btn btn-success btn-block" name="login" value="Masuk">
  74. </div>
  75. </form>
  76. </div>
  77. </div>
  78. </div><!-- /.col -->
  79. </div><!-- /.row -->
  80. </div><!-- /.col -->
  81. </div><!-- /.row -->
  82. </div><!-- /.container -->
  83. </section>
  84.  
  85. <!-- footer-bottom -->
  86. <div class="navbar navbar-inverse navbar-fixed-bottom footer-bottom">
  87. <div class="container text-center">
  88. <p class="text-center" style="color: #D1C4E9; margin: 0 0 5px; padding: 0"><small>e - Cuti</small></p>
  89. </div>
  90. </div><!-- /.footer-bottom -->
  91.  
  92. <!-- Bootstrap Core JavaScript -->
  93. <script src="libs/bootstrap/dist/js/bootstrap.min.js"></script>
  94.  
  95. </body>
  96. </html>
  97.  
  98.  
  99. Login otentikasi :
  100.  
  101. <?php
  102. // memulai session
  103. // memanggil file koneksi
  104. include("dist/config/koneksi.php");
  105.  
  106. // mengecek apakah tombol login sudah di tekan atau belum
  107. if(isset($_POST['login'])) {
  108. // mengecek apakah username dan password sudah di isi atau belum
  109. if(empty($_POST['username']) || empty($_POST['password'])) {
  110. // mengarahkan ke halaman login.php
  111. header("location: login.php?err=empty");
  112. }
  113. else {
  114. // membaca nilai variabel username dan password
  115. $username = $_POST['username'];
  116. $password = $_POST['password'];
  117. $akses = $_POST['akses'];
  118. // mencegah sql injection
  119. $username = htmlentities(trim(strip_tags($username)));
  120. $password = htmlentities(trim(strip_tags($password)));
  121. // memeriksa username di tabel admin
  122.  
  123. if($akses=="Admin"){
  124. $sql = "SELECT * FROM admin WHERE user_adm='". $username ."' AND pass_adm='". $password ."'";
  125. $ress = mysqli_query($conn, $sql);
  126. $rows = mysqli_num_rows($ress);
  127. $dataku = mysqli_fetch_array($ress);
  128. // mendaftarkan session jika username di temukan
  129. if($rows == 1) {
  130. // membuat variabel session
  131. $_SESSION['admin'] = strtolower($dataku['id_adm']);
  132. // mengarahkan ke halaman indeks.php
  133. header("location: index.php?login=success");
  134. }else{
  135. header("location: login.php?err=not_found");
  136. }
  137. }else if($akses=="Lead"){
  138. $aks = "Kepala Biro/Prodi";
  139. $sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
  140. $ress = mysqli_query($conn, $sql);
  141. $rows = mysqli_num_rows($ress);
  142. $dataku = mysqli_fetch_array($ress);
  143. // mendaftarkan session jika username di temukan
  144. if($rows == 1) {
  145. // membuat variabel session
  146. $_SESSION['leader'] = strtolower($dataku['npp']);
  147. // mengarahkan ke halaman indeks.php
  148. header("location: leader/index.php?login=success");
  149. }else{
  150. header("location: login.php?err=not_found");
  151. }
  152. }else if($akses=="Mng"){
  153. $aks = "Direktur";
  154. $sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
  155. $ress = mysqli_query($conn, $sql);
  156. $rows = mysqli_num_rows($ress);
  157. $dataku = mysqli_fetch_array($ress);
  158. // mendaftarkan session jika username di temukan
  159. if($rows == 1) {
  160. // membuat variabel session
  161. $_SESSION['manager'] = strtolower($dataku['npp']);
  162. // mengarahkan ke halaman indeks.php
  163. header("location: manager/index.php?login=success");
  164. }else{
  165. header("location: login.php?err=not_found");
  166. }
  167. }else if($akses=="Pgw"){
  168. $aks = "Pegawai";
  169. $sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
  170. $ress = mysqli_query($conn, $sql);
  171. $rows = mysqli_num_rows($ress);
  172. $dataku = mysqli_fetch_array($ress);
  173. // mendaftarkan session jika username di temukan
  174. if($rows == 1) {
  175. // membuat variabel session
  176. $_SESSION['pegawai'] = strtolower($dataku['npp']);
  177. // mengarahkan ke halaman indeks.php
  178. header("location: pegawai/index.php?login=success");
  179. }else{
  180. header("location: login.php?err=not_found");
  181. }
  182. }else{
  183. $aks = "Wakil Direktur";
  184. $sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
  185. $ress = mysqli_query($conn, $sql);
  186. $rows = mysqli_num_rows($ress);
  187. $dataku = mysqli_fetch_array($ress);
  188. // mendaftarkan session jika username di temukan
  189. if($rows == 1) {
  190. // membuat variabel session
  191. $_SESSION['supervisor'] = strtolower($dataku['npp']);
  192. // mengarahkan ke halaman indeks.php
  193. header("location: supervisor/index.php?login=success");
  194. }else{
  195. header("location: login.php?err=not_found");
  196. }
  197. }
  198. }
  199. }
  200. ?>
  201.  
  202.  
  203.  
  204.  

Ada 5 Jawaban

Hardiansyah
commented on 03 Mei 2020 00:41:01
  1. Assalamualaikum,.. $akses = $_POST['akses']; tidak memiliki nilai value dari form login
  2. jadi di buatkan satu form dengan nama akses (form select dropdown) untuk mengirim nilai nya ke $akses = $_POST['akses'];
Rafisqy Adhideva
commented on 03 Mei 2020 04:11:04
  1. Assalamualaikum...
  2.  
  3. mastah @hardiansyah itu mksd sy gk pake dropdown, jd sistem langsung baca semisal klo admin ya langsung ke dashboard admin...mksd sy gitu seh, otomatis...mohon pencerahannya mastah, terima kasih sebelumnya...
Hardiansyah
commented on 03 Mei 2020 17:30:08
  1. Assalamualaikum,.. $akses = $_POST['akses'];
  2. sama dengan $username = $_POST['username']; $password = $_POST['password'];
  3. yg artinya dikirim dari form halaman login pak, jadi kalau menggunakan cara tsb harus di buat di form login juga.
  4. Kalau ingin otomatis maka bisa dengan car buatkan tabel khusus akun yg login di dalamanya ada field kolom hak akses, jadi ketika user login di cek juga hak akses akun tersebut, lalu di buatkan juga sessionnya baru di redirect berdasarkan session tersebut
pagandeng salapang
commented on 05 Mei 2020 05:04:34
  1. Assalamualaikum,..
  2. kalo sy biasa buat tabel level akses, mis. spt digambar terlampir
Terdapat 1 File dilampirkan :
1. level.JPG (10 KB)
Rafisqy Adhideva
commented on 06 Mei 2020 01:43:49
  1. Assalamualaikum,.. terima kasih master @hardiansyah dan master @pagandeng salapang, sy coba dl...
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!

Online