此页面未正确重定向

时间:2011-04-24 13:35:43

标签: php session redirect login

我使用了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");}

2 个答案:

答案 0 :(得分:2)

用Blowski的话来解释:http://kb.mozillazine.org/The_page_is_not_redirecting_properly

这就像firefox达到了它的最大递归深度:它已经检测到看似无限的重定向循环

答案 1 :(得分:1)

上述脚本中文件的名称是什么?如果第一个脚本的名称是home.php,那么当用户访问home.php时,如果密码不正确,它将继续重新加载,因此Firefox将返回该消息。

或者,你的.htaccess中有什么东西导致它吗?