Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login(){
- global $db, $username, $errors;
- // grap form values
- $username = e($_POST['username']);
- $password = e($_POST['password']);
- // attempt login if no errors on form
- if (count($errors) == 0) {
- $query = "SELECT * FROM users WHERE username='$username' LIMIT 1";
- $results = mysqli_query($db, $query);
- $vypis = mysqli_fetch_array($results)
- if (password_verify ($vypis["password"], $password )){
- // user found logged
- // check if user is admin or user
- $logged_in_user = mysqli_fetch_assoc($results);
- if ($logged_in_user['user_type'] == 'admin') {
- $_SESSION['user'] = $logged_in_user;
- $_SESSION['success'] = "You are now logged in";
- header('location: index.php');
- }
- else {
- $_SESSION['user'] = $logged_in_user;
- $_SESSION['success'] = "You are now logged in";
- header('location: index.php');
- }
- }
- else {
- array_push($errors, "Wrong username/password combination");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement