2016-03-26 11 views
-2

Ich bin derzeit organisiert meine Dateien in entsprechende Ordner und ein Problem ist entstanden. Vor dem Ändern des Codes zum Organisieren der Dateien hat alles funktioniert. Jetzt, wenn ich versuche, mich anzumelden, anstatt auf "Staff/staff.php" umzuleiten, wird es auf "Staff/index.php" umgeleitet.Header-Funktion wird auf index.php statt der angegebenen Datei (PHP)

Der Code ist wie folgt:

<?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'); ?> 

Ist der Header das Problem?


EDIT

Das gleiche passiert mit meiner Abmelde Datei. Es wird auf "Staff/logout.php" statt auf "../logout.php" umgeleitet. Es funktionierte, bevor ich anfing, die Dateien zu organisieren.

Der Code für logout.php:

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

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

?> 
+1

Können Sie nach 'staff.php' – Panda

+0

Neben , haben Sie irgendwelche Redirects oder Rewrite-Regeln in einer '.htaccess' Datei? – Qirel

+0

Ich habe keine .htaccess-Datei –

Antwort

0

Haben Sie versucht:

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

und: dass

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

Ist das die index.php-Datei, die Sie gegeben haben, wenn ja, in der Form, vielleicht lassen Sie einfach Aktion leer, als könnte dies möglicherweise verursacht werden. –

Verwandte Themen