如何使用cookie进行标准登录以保持用户登录?

时间:2018-06-11 09:10:06

标签: javascript php

我正在制作登录系统,但我不知道如何制作cookie以保持用户登录。

<!DOCTYPE html>
    <html>
        <head>
            <title> login </title>
        </head>
        <body>

        <?php
            $cookie = false;
            $username = (isset($_POST['username']) ? $_POST ['username'] : 0);
            $password = (isset($_POST['password']) ? $_POST['password'] : 0);

        echo($username);
        echo($password);

        $con = db_connection();
        if (!$con)  {
            printf("Connect failed: %s/n", mysqli_connect_error());
            exit();
         } else {
            $query = "SELECT * FROM 'users' WHERE";
            $query = $query . "Username = '".$username."'";
            $query = $query . " AND Password = '".$password."'";

            $result = mysqli_query($con,$query);
        }
    var_dump($result);
        if(mysqli_num_rows($result)!=0) {
            $roq = mysqli_fetch_array($result);
            $cookie = true;
            if ($cookie = true) {
                echo "Logged in with cookies";
            }6
            extract($row,EXTR_PREFIX_ALL, "query");
            printf("<br/><br/>Welcome back");
            printf($username);
            printf("<br/>Congratulations - you have succ");
            printf("<br/>Your UserID");
            printf($query_UserId);
            }else{

            }
        mysqli_close($con);
    ?>

0 个答案:

没有答案