2016-03-26 7 views
-2

現在、ファイルを適切なフォルダに整理していますが、問題が発生しています。ファイルを整理するためにコードを変更する前に、すべてが機能しました。今すぐログインしようとすると、 'Staff/staff.php'にリダイレクトする代わりに、 'Staff/index.php'にリダイレクトされます。ヘッダ機能が指定されたファイル(PHP)の代わりにindex.phpにリダイレクトしています

コードは以下の通りです:

<?php 
    session_start(); 

    include("connectdb.php"); 

    //if the form has been submitted 
    if (isset($_POST['submitted'])){ 
    //get the information out of get or post depending on your form 
     $username = $_POST['username']; 
     $password = $_POST['password']; 

     global $db; 

     //sanitise the inputs! 
     $safe_username = $db->quote($username); 

     //run a query to get the user associated with that username 
     $query = "select * from user where username = $safe_username"; 
     $result = $db->query($query); 
     $firstrow = $result->fetch(); //get the first row 

     if (!empty($firstrow)) { 
      //check the passwords, if correct add the session info and redirect 
      $hashed_password = md5($password); 

      if ($firstrow['password'] == $hashed_password){ 
       $_SESSION['id'] = $firstrow['userID']; 
       $_SESSION['username'] = $firstrow['username']; 
       $_SESSION['fname'] = $firstrow['first_name']; 
       $_SESSION['lname'] = $firstrow['last_name']; 
       $_SESSION['staff'] = $firstrow['staff']; 

       if($firstrow['staff'] == 1) { 
        header("Location:Staff/staff.php"); 
        exit(); 
       } else { 
        //echo "Success!"; 
        header("Location:Customer/customer.php"); 
        exit(); 
       } 
      } else { 
       echo "<h1>Error logging in, password does not match</h1>"; 
      } 
     } else { 
      //else display an error 
      echo "<h1>Error logging in, Username not found</h1>"; 
     } 
    } 
?> 

<html> 
    <head> 
     <link rel="stylesheet" type="text/css" href="CSS/theme.css"> 
    </head> 
    <body> 
     <h1 class="register-title">Aston Animal Sanctuary</h1> 
     <div class="register"> 
      <!--<form method="link" action="staff.php"> 
       <input type="submit" value="Staff Login"> 
      </form>--> 
      <form action="index.php" method="post"> 
       <input type="text" class="register-input" name="username" placeholder="Username"> 
       <input type="password" class="register-input" name="password" placeholder="Password"> 
       <input type="submit" value="Login" class="register-button"> 
       <input type="hidden" name="submitted" value="TRUE" /> 
      </form> 
      <form method="link" action="register.php"> 
       <input class="register-button" type="submit" name="register" value="Register"> 
      </form> 
     <div> 
     <!--<a href="test1.php" class="button">Test</a>--> 
    </body> 
</html> 

<?php include('View/footer.html'); ?> 

は問題ヘッダーですか?同じことが私のログアウトファイルで発生


EDIT

。 '../logout.php'ではなく 'Staff/logout.php'にリダイレクトされます。私がファイルを整理する前にそれは働いていました。

logout.phpのためのコード:

<?php 
session_start(); //get the previous session info 
session_destroy(); //destroy it 

header("Location: ../index.php"); //redirect back to the start 

?> 
+1

をあなたはそれに加えて 'staff.php' – Panda

+0

を投稿することができますに'.htaccess'ファイルにリダイレクトや書き換えルールがありますか? – Qirel

+0

私は.htaccessファイルを持っていません –

答えて

0

あなたが試してみました:

header("Location: ./staff/staff.php"); 

と:

header("Location: ./customer/customer.php"); 
+0

あなたが与えたindex.phpファイルは、そういう場合にはフォームの中にあります。 –

関連する問題