0

このコード ブロックは、作成中のページのバックエンドに管理者としてログインするためのものです。私の「間違った情報」ステートメントをエコーする「else」ステートメントに解析します。基本的に、私がチェックして再確認したサーバー上で作成した資格情報が見つからないと言っています。また、接続スクリプトが機能していることも確認しました。私は困惑しています。どんな助けでも大歓迎です。

<?php
session_start();
if(isset($_SESSION["manager"])) {
  header("location: index.php");
  exit();
}
?>
<?php 
// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["username"]) && isset($_POST["password"])) {

    $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["username"]); // filter everything but numbers and letters 
      $password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters 
      // Connect to the MySQL database
      include "../php/connect_to_mysql.php";
      $sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); // Query the person
//------MAKE SURE PERSON EXISTS-----
$existCount = mysql_num_rows($sql); // Count the row nums
if ($existCount == 1) {
    while($row = mysql_fetch_array($sql)){
      $id = $row["id"];
    }
    $_SESSION["id"] = $id;
    $_SESSION["manager"] = $manager;
    $_SESSION["password"] = $password;
    header("location: index.php");
    exit();
  } else {
    echo 'That information is incorrect, <a href="index.php">try again</a>.';
    exit();
  }
}
?>

これはフォームコードです

<form name="adminform" id="adminform" method="post" action="admin_login.php">
              <div class="row collapse">
                <div class="large-2 columns">
                  <label class="inline">Username</label>
                </div>
                <div class="large-10 columns">
                  <input type="text" id="username" placeholder="JohnDoe" name="username">
                </div>
              </div>
              <div class="row collapse">
                <div class="large-2 columns">
                  <label class="inline">Password</label>
                </div>
                <div class="large-10 columns">
                  <input type="password" id="password" placeholder="Shazam" name="password">
                </div>
              </div>
              <button type="submit" name="button" id="button" class="radius button">Log In</button>
        </form>
4

1 に答える 1

3

問題は、$_POST 変数をチェックしている場合でも、フィルターを実行するときに $_SESSION 値を使用することです。$_POST で試してください。

// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["username"]) && isset($_POST["password"])) {
    $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]);
    $password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]);

    // ...
于 2013-08-09T20:24:38.160 に答える