2017-05-22 8 views
0

ユーザーの入力したユーザー名とパスワードを入力し、入力された詳細をユーザーの詳細を含むXML文書と照合する基本ログインページがあります。PHPログインページ常に誤ったユーザー名とパスワードを返す

ユーザー名とパスワードが正しい場合でも、PHPドキュメントには資格情報が正しくないことが表示されているという問題があります。

おかげ

<?php 

    if(isset($_GET['login'])) { 

     $id = ""; 
     $errors = ""; 
     $dom = DomDocument::load('../../data/customer.xml'); 

     if(empty($_GET['email'])) { 
      $errors .= "Email field cannot be empty <br />"; 
     } 
     else { 
      $inputEmail = $_GET['email']; 
     } 
     if(empty($_GET['password'])) { 
      $errors .= "Password field cannot be empty <br />"; 
     } 
     else { 
      $inputPassword = $_GET['password']; 
     } 

     if(isset($inputEmail) && isset($inputPassword)) { 

      $email = $dom->getElementsByTagName('email'); 
      $password = $dom->getElementsByTagName('password'); 

      for($i = 0; $i < $email->length; $i++) { 
       if($inputEmail == $email->item($i)->textContent && $inputPassword == $pwd->item($i)->textContent) { 
        $id = $dom->getElementsByTagName("id")->item($i)->textContent; 
        break; 
       } 
      } 

     } 

     if($id == "") { 
      $errors .= "Incorrect username or password"; 
     } 

     if($errors == "") { 
      echo true; 
     } 
     else { 
      echo $errors; 
     } 

    } 
?> 

XMLの要求、ここでは例として:

<customers> 
    <details> 
     <firstname>Example</firstname> 
     <lastname>Example</lastname> 
     <email>[email protected]</email> 
     <id>1</id> 
     <password>cb750e88</password> 
    </details> 
</customers> 
+1

XMLの例を挙げてください。 (機密データの変更) – FirstOne

+0

あなたの$ domに含まれていると考えられるものが含まれているか確認してください(Vardumpを実行してください) – Wep0n

+0

は$ _GETの代わりに$ _POSTをチェックしません。 – verhie

答えて

2

かわり$password$pwd変数を取っている:

if($inputEmail == $email->item($i)->textContent && $inputPassword == $pwd->item($i)->textContent) { 

はそれを置き換える:

if($inputEmail == $email->item($i)->textContent && $inputPassword == $password->item($i)->textContent) { 
+0

私はそのタイプミスを逃したとは思わない。助けてくれてありがとう! – Craig

+1

@FirstOne Yahは、 –

関連する問題