2011-04-24 129 views
1

我用從about.com以下腳本:http://php.about.com/od/finishedphp1/ss/php_login_code_2.htm該頁面未正確重定向

的問題是,幾次它給了我這個錯誤:頁面沒有正確重定向。 Firefox已經檢測到服務器以永不完成的方式重定向該地址的請求。 代碼:

<?php 

session_start(); 



// Process the POST variables 
$username = $_SESSION["user_name"]; 
//$password = $_POST["password"]; 


    // Set up the session variables 
    $_SESSION["user_name"] = $username; 

     $ugh = $_REQUEST['url_name']; 

      if($_POST){ 
      $_SESSION['user_name']=$_POST["user_name"]; 
      $_SESSION['password']=$_POST["password"]; 
      } 



       $secret = $info['password']; 

      //Checks if there is a login cookie 

      if(isset($_COOKIE['ID_my_site'])) 


      //if there is, it logs you in and directes you to the members page 

       { 
      $username = $_COOKIE['ID_my_site']; 

      $pass = $_COOKIE['Key_my_site']; 

    $check = mysql_query("SELECT user_name, password 
      FROM users WHERE user_name = '$username' 
      and url_name='$ugh'")or die(mysql_error()); 

      while($info = mysql_fetch_array($check)) 



      { 

       if (@ $info['password'] != $pass) 
       { 

        } 

        else 

       { 

        header("Location: home.php"); 



        } 

        } 

        } 


     //if the login form is submitted 

     if (isset($_POST['submit'])) { // if form has been submitted 



     // makes sure they filled it in 

      if(!$_POST['user_name'] | !$_POST['password']) { 

    die('You did not fill in a required field.'); 

     } 

// checks it against the database 



if (!get_magic_quotes_gpc()) { 

    $_POST['user_name'] = addslashes($_POST['user_name']); 


} 

$check = mysql_query("SELECT user_name,password 
    FROM users WHERE user_name = '".$_POST['user_name']."' 
    and url_name='".$ugh."'")or die(mysql_error()); 



     //Gives error if user dosen't exist 

      $check2 = mysql_num_rows($check); 

     if ($check2 == 0) { 

      die('That user does not exist in our database. 
      <a href=add.php>Click Here to Register</a>'); 

      } 

     while($info = mysql_fetch_array($check)) 

      { 

      $_POST['password'] = md5($_POST['password']); 
      $_POST['password'] = $_POST['password']; 



      //gives error if the password is wrong 



      if (@ $_POST['password'] != $info['password']) { 

      die('Incorrect password, please try again'); 


       } 

       else 

      { 


      // if login is ok then we add a cookie 

     $_POST['user_name'] = stripslashes($_POST['user_name']); 

    $hour = time() + 3600; 

      setcookie(ID_my_site, $_POST['user_name'], $hour); 

      setcookie(Key_my_site, $_POST['password'], $hour); 



      //then redirect them to the members area 

      header("Location: home.php"); 

      } 

      } 

      } 

      else 

      { 



      // if they are not logged in 

      ?> 

第二碼:

然後我用下面,以確保他們的登錄是正確的每個成員頁:

 // Process the POST variables 
     $email = $_SESSION["user_name"]; 


    // Set up the session variables 
    $_SESSION["user_name"] = $username; 


    if(!isset($_SESSION['user_name'])) { header("Location: log.php");} 
+0

@Zoolway更新問題的似乎無休止的循環。 – KPO 2011-04-24 13:42:59

回答

1

什麼是文件的名字在上面腳本?如果第一個腳本的名稱是home.php,那麼當用戶訪問home.php時,如果密碼不正確,它將繼續重新加載,因此Firefox將返回該消息。

另外,你有什麼在你的.htaccess是造成它?

+0

第一條是log.php。 htaccess有一個文件,它將傳入的用戶名顯示一個頁面,所以想象一下blowski.domain.com .. – KPO 2011-04-24 14:09:26

+0

@KPO嗯,你可以發佈你的.htaccess文件的內容嗎?這通常是錯誤重定向的原因。 – 2011-04-24 14:23:47

+0

@blowski查看問題。只是更新了它。 – KPO 2011-04-24 14:29:58

相關問題