登录后空白页

时间:2020-02-17 13:49:17

标签: php authentication

我正在尝试使用PDO和会话创建登录/注册系统,并且用户可以创建其帐户,并且可以访问“欢迎”页面,但是当注销并尝试使用有效的用户名和密码进行登录时,它将发送我到一个空白的php页面,我在互联网上看了一下,空白的php页面意味着语法错误,我找不到任何语法错误。 顺便说一句我尝试用任何密码键入任何用户名,它仍然将我发送到空白的php页面 这是我的代码: Config.php

class config {

    public static function connect()
    {
        $host = "localhost";
        $username = "root";
        $password = "";
        $dbname = "logintest";

        try{

            $bdd = new PDO("mysql:host=$host;dbname=$dbname",$username,$password);

            $bdd->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);


        }catch(PDOException $e)
        {
            echo "Connection échoué" . $e->getMessage();
        }
        return $bdd;
    }
}

?>

我的process.php(这是我认为问题来自的地方:


session_start();

    include_once("config.php");

        if(isset($_POST['register']))
        {
            $bdd = config::connect();
            $username = $_POST['username'];
            $email = $_POST['email'];
            $password = $_POST['password'];

    if(insertDetails($bdd,$username,$email,$password))
    {
        $_SESSION['username'] = $username;
        header("Location: profile.php");
    }

}


    if(isset($_POST['login']))
    {
        $bdd = config::connect();
        $username = $_POST['username'];
        $password = $_POST['password'];

    if(checkLogin($bdd,$username,$password))
        {
            $_SESSION['username'] = $username;
            header("Location: profile.php");
        }
    else{
        echo "Le mot de passe ou le nom d'utilisateur sont incorrect";
    }
}


    function insertDetails($bdd,$username,$email,$password)
        {
            $query = $bdd->prepare("

                INSERT INTO users (username,email,password)

                VALUES(:username,:email,:password)

                ");
            $query->bindParam(":username",$username);
            $query->bindParam(":email",$email);
            $query->bindParam(":password",$password);

    return $query->execute();
}


    function checkLogin($bdd,$username,$password)
    {
        $query = $bdd->prepare("

            SELECT * From users WHERE username=:username AND password=:password

        ");

        $query->bindParam(":username", $username);
        $query->bindParam(":password", $password);

        $query->execute();

    // Check how many rows are returned

        if ($query->rowCount() == 1)
        {
            return true;
        }
        else {
            return false;
        }

    }

我的profile.php:

session_start();

include_once("config.php");

echo "Bienvenue " . $_SESSION['username'] . "  ";

echo "<a href='logout.php'>Se deconnecter</a>". "  ";

echo "<a href='update.php'>Mettre a jour le profile</a>" . "  ";

echo "<a href='delete.php'>Supprimer mon compte</a>". "  ";

?>```
and my logout.php :
```<?php

session_destroy();

header("Location: index.html");
?>

或者这是我正在从事的项目:https://github.com/AmrouHab/LoginRegister/tree/master/neptunetest

我会帮忙的 谢谢 (顺便说一句,我的法语不好,我很抱歉)

1 个答案:

答案 0 :(得分:0)

好吧,我找到了解决方案 我忘了在process.php中放一个大写的“ L”

 if(isset($_POST['login']))

我已将其更正为

 if(isset($_POST['Login']))

,现在可以正常工作了。 感谢您的关注。