Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login_user(){
- global $con;
- if(isset($_POST['submit'])){
- //row dari database
- //get from
- $email = $_POST['email'];
- $email_query=query("SELECT * FROM learn_users WHERE user_email='{$email}'");//sql language
- if(mysqli_num_rows($email_query)==0){
- //mysqli_num_rows akan kira berapa row dalam table itu
- $_SESSION['email_not_valid']=$email;//sebelum redirect tu tambah nih blh masukkan
- redirect("index.php");
- }else{
- $password = escape_string($_POST['password']);
- $query = query ("SELECT * FROM learn_users WHERE user_email = '{$email}' AND user_password = '{$password}'");
- confirm($query);
- while($row = fetch_array($query)){
- $db_user_email = $row['user_email'];
- $db_user_password = $row['user_password'];
- $db_user_role = $row['user_role'];
- $db_username=$row['username'];
- }
- //set the user role, here is user role admin function, klaw user enter punya detail same as database will send the detail to $_session for hold the detail
- if($email == $db_user_email && $password == $db_user_password && $db_user_role == "admin"){
- $_SESSION['user_email'] = $db_user_email;
- $_SESSION['user_role'] = $db_user_role;
- $_SESSION['username']=$db_username;
- //Go to the right page if password and email is correct and user role is admin
- redirect("../admin/index.php");
- }
- if($email == $db_user_email && $password == $db_user_passwor && $db_user_role == "student"){
- $_SESSION['user_email'] = $db_user_email;
- $_SESSION['user_role'] = $db_user_role;
- $_SESSION['username'] = $db_username;
- redirect("../student/index.php");
- }elseif($$email !== $db_username && $password !== $db_user_password){
- redirect("index.php");
- }else{
- //Go to login page if two IF above not satisfied
- redirect("index.php");
- }
- }
- }
- }
- function admin_session(){
- if(!isset($_SESSION['user_email']) && $_SESSION['user_role']!=='admin'){//session hanya boleh pegang satu account sahaja, untuk pakai remember me (keguaan)}
- //isset mesti ada data
- }else{
- }
- }
- function student_session(){
- if(isset($_SESSION['user_email']) && $_SESSION['user_role']=='student'){
- //stay in student page
- }else{
- redirect("../login/index.php");
- }
- }
- function student_logout(){
- unset($_SESSION['user_email']);
- unset($_SESSION['user_role']);
- unset($_SESSION['username']);
- redirect("../login/index.php");
- }
- function admin_logout(){
- unset($_SESSION['user_email']);
- unset($_SESSION['user_role']);
- unset($_SESSION['username']);
- //unset buang data
- //Delete all session variables, xkan putar balik
- //session_destroy();
- //Jump to login page
- redirect("../login/index.php");
- }
- function email_check(){//kalau user berjaya ditambah pakai function tersebut
- if(empty($_SESSION['email_not_valid'])){
- //if session is empty, then nt display any data.
- }else{
- //if session is not empty, then display message
- ?>
- <div class ="alert alert-danger alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span></button>
- <strong>Strong;</strong><b><?php echo $_SESSION['email_not_valid']?></b>is not registered into this system.
- </div>
- <?php
- unset($_SESSION['email_not_valid']);
- }
- }
- <?php require MODEL_ROOT . '/admin/functions.php'; ?>
- <div class="container">
- <div class="row">
- <div class="col-md-4 col-md-offset-4">
- <div class="login-panel panel panel-default">
- <div class="panel-heading">
- <h3 class="panel-title">Please Sign In</h3>
- </div>
- <div class="panel-body">
- <?php
- email_check();//for email checking purposed
- ?>
- <form role="form" action="" method="post">
- <?php login_user() ?>
- <fieldset>
- <div class="form-group">
- <!--for checking the user have enter email format to this columm, if user enter wrong format, it will have error-->
- <input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>
- </div>
- <div class="form-group">
- <input class="form-control" placeholder="Password" name="password" type="password" value="">
- </div>
- <div class="checkbox">
- <label>
- <input name="remember" type="checkbox" value="Remember Me">Remember Me
- </label>
- </div>
- <!-- Change this to a button or input when using this as a form -->
- <input type="submit" name="submit" class="btn btn-lg btn-success btn-block" value ="Login">
- <!--<a href="index.html" class="btn btn-lg btn-success btn-block">Login</a>-->
- </fieldset>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- <?php require MODEL_ROOT . '/admin/functions.php';?>
- <?php require VIEW_ROOT . '/templates-student/header.php';
- student_session();
- ?>
- <div id="wrapper">
- <?php require VIEW_ROOT.'/templates-student/navigation.php';?>
- <!-- Page Content -->
- <div id="page-wrapper">
- <div class="container-fluid">
- <div class="row">
- <div class="col-lg-12">
- <h1 class="page-header">Blank</h1>
- <?php
- if($pages_url=="add_subject"){
- require VIEW_ROOT . '/templates-admin/form-admin/form_add_subject.php';
- }elseif($pages_url == "no page"){
- echo "No page displayed";
- }elseif($pages_url == "logout"){
- admin_logout();//logout function
- }elseif($pages_url=="manage_subject"){
- manage_subject();
- delete_subject();
- }elseif($pages_url=="edit_subject"){
- require VIEW_ROOT . '/templates-admin/form-admin/form_edit_subject.php';
- }
- else{
- }
- ?>
- </div>
- <!-- /.col-lg-12 -->
- </div>
- <!-- /.row -->
- </div>
- <!-- /.container-fluid -->
- </div>
- <!-- /#page-wrapper -->
- </div>
- <!-- /#wrapper -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement