0

I have Sign-in script PHP single user working fine. But I want to add sign-in multiuser like superadmin, admin and user. I have need please help me...

I have need login_type full code

Sign-in login_type "superadmin" header location "superadmin.php"

Sign-in login_type "admin" header location "admin.php"

Sign-in login_type "user" header location "user.php"

Sign-in php script here

     <?php

       $username = $password = "";
        $username_err = $password_err = "";
        if($_SERVER["REQUEST_METHOD"] == "POST"){

    if(empty(trim($_POST["username"]))){
        $username_err = "Please enter username.";
    } else{
        $username = trim($_POST["username"]);
    }

    if(empty(trim($_POST["password"]))){
        $password_err = "Please enter your password.";
    } else{
        $password = trim($_POST["password"]);
    }

    if(empty($username_err) && empty($password_err)){
        $sql = "SELECT user_id, username, password FROM login WHERE username = ?";

        if($stmt = mysqli_prepare($conn, $sql)){
            mysqli_stmt_bind_param($stmt, "s", $param_username);

            $param_username = $username;

            if(mysqli_stmt_execute($stmt)){
                mysqli_stmt_store_result($stmt);

                if(mysqli_stmt_num_rows($stmt) == 1){                    

                    mysqli_stmt_bind_result($stmt, $user_id, $username, $hashed_password);
                    if(mysqli_stmt_fetch($stmt)){
                        if(password_verify($password, $hashed_password)){
                            session_start();
                            $_SESSION["loggedin"] = true;
                            $_SESSION["user_id"] = $user_id;
                            $_SESSION["username"] = $username;


                            header("location: index.php");

                        } else{
                            $password_err = "The password you entered was not valid.";
                        }
                    }
                } else{
                    $username_err = "No account found with that username.";
                }
            } else{
                echo "Oops! Something went wrong. Please try again later.";
            }
        }

        mysqli_stmt_close($stmt);
    }

    mysqli_close($conn);
}
    ?>
  • This question appears to be off-topic because it is about web development which is off-topic at Pro Webmasters. Web development questions may be asked at Stack Overflow but be sure to read their FAQ before posting to ensure your question meets their guidelines. In its current form, this question does not meet their guidelines. – John Conde May 18 '19 at 18:44
0

You have maintain a separate column in table like login_type for every user and store 1 for superadmin, 2 for admin, 3 for others ...etc,

    $sql = "SELECT user_id, username,type_login password FROM login WHERE username = ?";
    mysqli_stmt_bind_result($stmt, $user_id, $username, $type_login, $hashed_password);

Edit above two lines and this if($type_login==1){ check below

             if(mysqli_stmt_fetch($stmt)){
                    if(password_verify($password, $hashed_password)){
                        session_start();
                        $_SESSION["loggedin"] = true;
                        $_SESSION["user_id"] = $user_id;
                        $_SESSION["username"] = $username;
                        if( $type_login==1){
                            header("location: superadmin.php");
                        }elseif($type_login==2){
                            header("location: admin.php");                                
                        }elseif($type_login==3){
                            header("location: user.php");
                        }
                    } else{
                        $password_err = "The password you entered was not valid.";
                    }
                }

If your username is unique the do like this...

                            if($username=='SuperAdmin'){
                                header("location: superadmin.php");
                            }elseif($username=='Admin'){
                                header("location: admin.php");                                
                            }elseif($username=='Others'){
                                header("location: user.php");
                            }
| improve this answer | |
  • hello sir Fatal error: Uncaught Error: Cannot use object of type mysqli_stmt as array in D:\xammp\htdocs\raisebux\admin\sign-in.php:45 Stack trace: #0 {main} thrown in D:\xammp\htdocs\raisebux\admin\sign-in.php on line 45 – Amitabh Kr May 18 '19 at 12:58
  • if($stmt['type_login']=='1'){ //45 – Amitabh Kr May 18 '19 at 12:59
  • database in a table field name is type_login superadmin 1 – Amitabh Kr May 18 '19 at 13:01
  • if($stmt['type_login']==1){ //45 also use – Amitabh Kr May 18 '19 at 13:02
  • I just give as example . . . See the basics of mysqli_stmt_fetch – Rasa Mohamed May 18 '19 at 13:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.