|
|
|
ขอความ Ajax login อยากกำหนดสิทธิ์ระดับการเข้าใช้งานครับ |
|
|
|
|
|
|
|
Login.php
Code (PHP)
<?php
session_start();
include_once("db.php");
if(isset($_POST['login_button'])) {
$user_email = trim($_POST['user_email']);
$user_password = trim($_POST['password']);
$sql = "SELECT aid, user, pass, email , rule FROM admin_system WHERE email='$user_email'";
$resultset = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
$row = mysqli_fetch_assoc($resultset);
if($row['pass']==$user_password){
echo "ok";
$_SESSION['user_session'] = $row['aid'];
} else {
echo "email or password does not exist."; // wrong details
}
}
?>
Login.js
Code (JavaScript)
$('document').ready(function() {
/* handling form validation */
$("#login-form").validate({
rules: {
password: {
required: true,
},
user_email: {
required: true,
email: true
},
},
messages: {
password:{
required: "<div class='text-danger'> please enter your password </div>"
},
user_email: " <div class='text-danger'> please enter your email address </div>",
},
submitHandler: submitForm
});
/* Handling login functionality */
function submitForm() {
var data = $("#login-form").serialize();
$.ajax({
type : 'POST',
url : 'login.php',
data : data,
beforeSend: function(){
$("#error").fadeOut();
$("#login_button").html('<i class="icon-spinner9 spinner mr-2"></i> sending ...');
},
success : function(response){
if(response=="ok"){
$("#login_button").html('<i class="icon-spinner9 spinner mr-2"></i> Signing In ...');
setTimeout(' window.location.href = "welcome.php"; ',4000);
} else {
$("#error").fadeIn(1000, function(){
$("#error").html('<div class="alert alert-warning border-0 alert-dismissible"> '+response+' !</div>');
$("#login_button").html('<span class="glyphicon glyphicon-log-in"></span> Sign In');
});
}
}
});
return false;
}
});
ผมอยากจะกำหนดว่า ถ้าสิทธิ์เป็น admin จะไปให้หน้า นี้ๆๆ หรือ เป็น สิทธิ์แค่ office จะไปหน้านี้ๆๆ
ตามที่ code ผมต้องกำหนดยังไงครับ
หรือ ถ้ามีวิธีที่ง่ายกกว่านี้แนะนำได้ไหมครับ
Tag : PHP, Ajax, jQuery
|
|
|
|
|
|
Date :
2019-01-15 11:22:51 |
By :
1404727839563428 |
View :
1495 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เพิ่มฟิวเข้าไปในฐานข้อมูลอีกครับ
อาจจะเป็น level หรือ status
เวลาบันทึกเข้าไปอาจเป็นตัวเลขหรือ ข้อความ
1 = admin
2 = office
แล้วก็เอามาเข้าเงื่อนไข
Code (PHP)
if($row['pass']==$user_password){
echo "ok";
$_SESSION['user_session'] = $row['aid'];
$_SESSION['status_session'] = $row['status'];
} else {
echo "email or password does not exist."; // wrong details
}
เวลาแสดงข้อมูล
Code (PHP)
if($_SESSION['status_session']=='1'){
//เอาหน้าหรือเมนูมาใส่ของ admin
}else if ($_SESSION['status_session']=='2'){
//เอาหน้าหรือเมนูของ office
}
ปล.เป็นแค่หลักการเบื้องต้น
|
|
|
|
|
Date :
2019-01-15 13:48:19 |
By :
nobetaking |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|