I kodu çalıştırdığınızda bu PHP Yönetici Giriş kodu, ben istiyorum Page yüklemez

2 Cevap

@mysql_select_db(fcs)
  or die("Unable to select Database");

//check if the form has been submitted
if(isset($_POST['submit'])){
  $msg="";

  //VALIDATE form information
  if(empty($_POST['uname'])){
    $msg="Please enter your username.";
  }

  if(empty($_POST['upass'])){
    $msg .="Please enter your password.";
  }



  //check length of password
  if(strlen($_POST['upass']) > 6){
    $msg .="Invalid password.";
  }

  if(empty($msg)){


    $sql = "SELECT uname,upass FROM administrator WHERE user ='".$_POST['uname']."'";
    $sql .= "AND password ='".md5($_POST['password'])."'";

    if(!$res = mysql_query($sql)){
      $msg.=mysql_error();
    }else{
      //user exists in system, set the session variables
      if (mysql_num_rows($res) == 1) {

        while($row = mysql_fetch_assoc($res)){
         // the user name and password match,
          $_SESSION['uname'] = $row['uname'];
          $_SESSION['upass'] = $_POST['upass'];

          //Now go to the main page
          header('location../admin.php');
        }
      }else{
        $msg = "Your login details did not match";
      }//end numrows check
    }//end res check
  }


}//end submit check
?>

Not:

I want to load the (admin.php) Page , if the user name and password was correct else just disply out a message:

2 Cevap

header-Function bu gibi kullanılmalıdır:

header('Location: ../admin.php');

Böyle tam mutlak bir URL belirtilmiş Ve eğer daha iyi olurdu:

header('Location: http://www.example.com/admin.php');

(Çoğu tarayıcı çok göreli URL desteklemese de) RFC 2616 mutlak URI olmak bunu gerektirir olmasıdır:

Location = "Location" ":" absoluteURI

Bulunduğunuz konum başlık olmalıdır:

header('Location: http://www.example.com/admin.php');

ve kullandığınız script üstündeki oturumu başlatmak gerekir:

session_start();

Bu oturum başlatma kodu $ _SESSION değişkenlere erişim ihtiyacı her sayfanın başında olmalıdır.