首页 > 解决方案 > 登录后如何将用户引导到另一个站点?

问题描述

我知道有很多关于制作登录系统的教程。但奇怪的是我的代码不起作用。

它在 password_verify 之前一直有效。

这是我的 index.php(用于登录)

<form id="sign-in" method="post">
            <input id="input" type="text" name="name" tabindex="1" placeholder="Benutzername" required><br>
            <input id="input" type="password" name="password"  tabindex="2" placeholder="Passwort" required><br>
            <input id="input" class="button" type="submit" name="submit" value="Einloggen"><br>
            <a href="accounts/account-not-found" id="account-not-found">Account wurde nicht gefunden?</a>
      </form>
      <?php

      if(isset($_POST["submit"])){
        require("mysql.php");
        $stmt = $mysql->prepare("SELECT * FROM accounts WHERE USERNAME = :user"); //USERNAME CHECK
        $stmt->bindParam(":user", $_POST["name"]);
        $stmt->execute();
        $count = $stmt->rowCount();
        if($count == 1){
          // USERNAME IST Frei
          $row = $stmt->fetch();
          if(password_verify($_POST["password"], $row["PASSWORD"])){
            session_start();
            $_SESSION["name"] = $row["USERNAME"];
            header("Location: internal-area/home/");
          }
          else{
            echo "Das Passwort ist falsch"; //GERMAN for Password is wrong
          }
        }
        else{
          echo "Der Login ist fehlgeschlagen"; //GERMAN for Login has failed
        }
      }
       ?>

我的“内部区域/home/index.php”:

    <?php

  session_start();
  if(!isset($_SESSON["name"])){
    header("Location: ../../"); // ../../ leads to my index.php for login (see above)
    exit;
  }

 ?>

我希望你能帮助我。如果缺少任何信息,请告诉我:)

丹尼尔。

标签: phpauthentication

解决方案


我拼错了

if(!isset($_SESSON["name"])){
    header("Location: ../../"); // ../../ leads to my index.php for login (see above)
    exit;
  }

它必须是 $_SESS I ON["name"]


推荐阅读