php - 此页面未正确重定向

标签 php session redirect authentication

我使用了 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 

           ?> 

第二个代码:

然后在每个成员(member)页面上,我使用以下内容来确保他们的登录正确:

      // 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");}

最佳答案

套用布洛夫斯基的话:http://kb.mozillazine.org/The_page_is_not_redirecting_properly

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

关于php - 此页面未正确重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5770789/

相关文章:

java - 第二次提交 multipart/config 后出现 NullPointerException - Tomcat

php - youtube-dl正在下载php文件而不是视频

php - Kevin Luck 的 jQuery 日期选择器插件 - 动态设置结束日期

php - 如何在laravel 5.1中访问子函数内父函数的参数

python - Django - 除非刷新页面,否则 session 变量不会更改

php - 登录页面 session 信息防止双重登录

redirect - 如何通过 301 重定向移动 URL 并保留页面的 Facebook 点赞和 Open Graph 信息?

javascript - 选中复选框时调用 Ajax 或提交按钮

django - 基本 HTTP 问题 : two session variables with different expiry dates?

javascript - 优化重定向代码