Coding Class

Quizgum : Project 1-7 : to handel login

To handle login

What we created in the previous tutorial is the login form.
This time, let's handle the login process.
I use a session or a cookie to log in.
I use a session, so I'll proceed with the session.
First, let's create a session file.




php image

And now let's create a source that handles login.


    include "../include/session.php";
    include "../include/dbConnect.php";

    $memberId = $_POST['memberId'];
    $memberPw = sha1($memberPw = $_POST['memberPw']);

    $sql = "SELECT * FROM member WHERE userId = '{$memberId}' AND password = '{$memberPw}'";
    $res = $dbConnect->query($sql);

    $row = $res->fetch_array(MYSQLI_ASSOC);

    if($row != null) {
        $_SESSION['ses_userid'] = $row['userId'];
        echo "<script>location.href='/myProject/';</script>";

    if($row == null){
        echo 'Login failure ID and password do not match';


php image

The above sources don't have to be hard at all. It's surprisingly simple.
Put the ID and password in the SELECT statement and divide them according to whether there is a match.
If so, it creates a session. If not, we don't make it.
Then it is the end.
This is really the end. This will create a session and you will be logged in.
This is the logout function. ^^;