Index.php登录功能修复

时间:2018-06-19 11:28:16

标签: php html function login

我有一个使用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>

还有loginfunc

<?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
            {

            }
        }
    }
?>

0 个答案:

没有答案