php mysql login function

Codes here !

Moderators: egami, macek, gesf

Post Reply
juulphp
New php-forum User
New php-forum User
Posts: 18
Joined: Tue Jan 24, 2017 5:41 am

Wed May 17, 2017 3:18 am

I have a login script that retrieve data from the MySQL database. Now I want to work with features. For example, if a user has function = 1, he will see a different page than user 2 that has function = 2. Also, user 1 may not come on user 2 page two that is then protected.

This is my checklogin.php:

Code: Select all

<?php
//Lees het config bestand
require_once'config.php';

//lees de formulier velden

$username = mysqli_real_escape_string($mysqli, $_POST['username']);
$password = mysqli_real_escape_string($mysqli, $_POST['password']);

if(strlen($username) > 0 && strlen($password) > 0) {

    //versleutel het wachtwoord

    $password = sha1($password);

    //maak de query

    $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password' AND functie = '1' ";
//voer de query uit
    $result = mysqli_query($mysqli, $query);

    //controleer of de login correct was

    if(mysqli_num_rows($result) == 1)

        //start de sessie
    {
        session_start();
        // sla de username op in de sessie
        $_SESSION['username'] = $username;
        //stuur door naar de homepage
       echo("<script>window.location = 'dashboard.php';</script>");
    }  else {
        echo "Username or Password wrong!";
    }
}       else {
        echo "Try again!";
    }

?>

How can I do this this in PHP?

chorn
php-forum Active User
php-forum Active User
Posts: 323
Joined: Fri Apr 01, 2016 2:18 am

Sun May 21, 2017 10:14 pm

create a table "permissions" and store the user_id along with the function. then you can check against these permissions on other pages.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests