login system geht nicht?


31.01.2024, 18:38

Hier mein der nötige Code (ich weis etwas unsauber und sehr viel aber ist das erste mal das ich sowas mache)

Verbindung zur Datenbank:

<?php
$serverName = "localhost";
$dBUserName = "root";
$dBPassword = "";
$dBName = "test";


$conn = mysqli_connect($serverName, $dBUserName, $dBPassword, $dBName);



if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

Login php:

<?php
  session_start();
  ?>
<html>
    <section class="signup-form">
     <div class="wrapper">
        <div class="form-box login">
            <h2>Login</h2>
            <form action="includes/login.inc.php" method="post">
                <div class="input-box">
                    <span class="icon">
                        <ion-icon name="mail"></ion-icon>
                    </span>
                    <input type="text" required name="uid">
                    <label>Username</label>
                </div>
                <div class="input-box">
                    <span class="icon"><ion-icon 
                        name="lock-closed"></ion-icon></span>
                    <input type="password" required name="pwd">
                    <label>Password</label>
                </div>
                <button type="submit" class="btn">Login</button>
                <div class="login-register">
                    <p>Don't have an account?<a href="http://localhost/sso%20projekt/signup.php"
                        class="register-Link"> Register</a></p>
                </div>


                <?php
    if (isset($_GET["error"])) {


        if ($_GET["error"] == "emptyinput") {
            echo "<p> Fill in all fields </p>";
        }



        else if ($_GET["error"] == "wronglogin") {
            echo "<p> Incorrect information </p>";


        }
        }
    ?>
            </form>
        </div>
    </div>
</section>


    <?php
    include_once 'footer.php';
?>

login.inc.php

<?php
session_start();


<?php


if (isset($_POST["submit"])) {


    $username = $_POST["uid"];
    $pwd = $_POST["pwd"];


    require_once 'dbh.inc.php';
    require_once 'functions.inc.php';


    if (emptyInputLogin($username, $pwd) !== false) {
        header("location: ../login.php?error=emptyinput");
        exit();
    }


    loginUser($conn, $username, $pwd);
}
else{
    header("location: ../login.php");
    exit();
}

functions.inc.php

function emptyInputLogin($username, $pwd) {
    $result;
    if (empty($username) || empty($pwd)) {
        $result = true;
        }   
        else {
        $result = false;
        }
    return $result;
}


function loginUser($conn, $username, $pwd) {
    $uidExists = uidExists($conn, $username);


    if ($uidExists === false) {
        header("location: ../login.php?error=wronglogin"); 
        exit();
    }


    $pwdHashed = $uidExists["usersPwd"];
    $checkPwd = password_verify($pwd, $pwdHashed);


    if ($checkPwd === false) {
        header("location: ../login.php?error=wronglogin"); 
        exit();
    }
    else if ($checkPwd === true) {
        session_start();
        $_SESSION["userid"] = $uidExists["usersId"];
        $_SESSION["useruid"] = $uidExists["usersUid"];
        header("location: ../Wishlist.php?"); 
        exit();
    }    
}
JokesOnYou  31.01.2024, 18:31

Jeder wird deinen Code brauchen um sehen zu können wo der Fehler ist.

Rike456 
Fragesteller
 31.01.2024, 18:43

hab ihn jetzt

hinzugefügt

xTheForza  31.01.2024, 18:31

Code wäre schonmal nicht schlecht.

Rike456 
Fragesteller
 31.01.2024, 18:43

ist drin

1 Antwort

Dein Formular verschickt keinen Eintrag namens submit. Du könntest deinen Button damit ausstatten.

<button name="submit" type="submit" class="btn">Login</button>

Beim Drüberfliegen ist mir zudem aufgefallen, dass

  • dein Dokument keinen Doctype hat; diese Angabe ist nicht optional
  • dein Dokument keinen Titel (title) hat (ebenfalls eine Pflichtangabe für ein valides HTML-Dokument)
  • du keine Zeichenkodierung vorgibst, was allerdings von Vorteil wäre, wenn du Daten via Formular verschickst; ich würde UTF-8 vorgeben:
<meta charset="utf-8">
Rike456 
Fragesteller
 31.01.2024, 19:06

omg du rettest mir das leben ich sitze so lange schon hier dran der tipp mit dem button war richtig DANKE danke danke

1