首页 > 解决方案 > Index.php 登录功能修复

问题描述

我有一个使用 loginfunc 函数的 index.php,它可以让用户登录。但奇怪的是,当您单击登录时,什么也没有发生。下面是 index.php 的代码。我无法弄清楚问题是什么,因为我没有收到错误消息,也没有看到错误,因此什么也没发生。

<?php
    require_once('functions/loginfunc.php');
    include_once("globals.php");
    $username = $_POST['username'];
    $passwort = $_POST['passwort']; 
    if (isset($_POST['register'])) {
        header("Location: /register.php");
    }

    if (isset($_POST['login'])) {
        loginfunc();
    }
?>

<html>
<head>
    <script type="text/javascript">
        document.getElementById("registerbutton").onclick = function () {
            location.href = "/register.php";
        };
    </script>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <title> Coiffure Creation Login </title>
</head>

<body>
    <a href="index.php">
        <img src="https://doriansandbox.toolmaster.ch/images/creation-coiffure-logo-neu.png" align="middle">
    </a> 
    <div id="login">
        <form method="POST" action="">

            Username:<br>
            <img src="/images/figure.png" alt="Icon" height="42" width="42>">
            <input type="text" name="username"><br>

            Passwort:<br> 
            <img src="/images/Key_lock.png" alt="Icon" height="42" width="42>">
            <input type="password" name="passwort"><br>

            <input type="submit" name="login" value="Login" />
            <input type="submit" name="register" value="Neuen User erstellen" />
        </form>
    </div>
</body

</html>

和登录函数

<?php
    function loginfunc() {
        session_start();
        include 'globals.php';
        if(empty($_POST["username"]) || empty($_POST["passwort"]))
        {
            echo "Bitte tragen Sie Ihr Passwort und Benutzername ein";
        }
        else {
            $query = "SELECT * FROM benutzer WHERE username = '$username'";
            $result = mysqli_query($con, $query);
            if(mysqli_num_rows($result) > 0)
            {
                while($row = mysqli_fetch_array($result))
                {
                    if(password_verify($passwort, $row["password"]))
                    {
                        session_start();
                        $_SESSION['username'] = $username;
                        header("Location:dashboard.php");
                    }
                    else
                    {
                        echo "Kevin";
                    }
                }
            }
            else
            {

            }
        }
    }
?>

标签: phphtmlfunctionlogin

解决方案


推荐阅读