小编Vie*_*edt的帖子

在php中创建一个非常简单的1用户名/密码登录

我想只为一个用户进行一次登录而不存储在数据库中,但我似乎无法使其工作.

我的代码:login.php

<html>
<head>
    <title>Login</title>
</head>
    <h3>Add entry</h3>
    <p> Add another Article</p>
    <form action="trylog.php" method = "post">
        <label for="username">Username</label> <input type="username" id="usename" name="username"><br /><br />
        <label for="password">Password:</label> <input type="text" id="password" name="password"><br /><br />
        <button type = "submit">Login</button>
    </form>
</html>
Run Code Online (Sandbox Code Playgroud)

trylog.php

<html>
    <title>Login</title>
    <body>
        <?php
        $usr = "admin";
        $psw = "password";
        $username = '$_POST[username]';
        $password = '$_POST[password]';
        //$usr == $username && $psw == $password
        session_start();
        if ($_SESSION['login']==true || ($_POST['username']=="admin" && $_POST['password']=="password")) {
            echo "password accepted";
            $_SESSION['login']=true;
        }else {
            echo "incorrect login"; …
Run Code Online (Sandbox Code Playgroud)

php

16
推荐指数
2
解决办法
25万
查看次数

标签 统计

php ×1