-2

我刚刚发生了一件非常奇怪的事情;我的登录脚本在我的计算机上运行良好。我刚刚使用我的主机将所有数据库和新站点重新上传到我的新测试服务器。但是,当我登录并按下提交时,它只会在顶部显示用户名和密码,就好像我是他们的 var_dump 一样。

这有什么原因吗?

这就是显示

string(3) "s17" string(32) "PASSWORD HASH HERE"

感谢您的任何帮助。

编辑。抱歉,这是我的代码,它有点长,我知道你会说我为什么要使用旧的 mysql_* 东西,但我很快就会转向 PDO,我现在正在学习它。

<?php

// Start Session to enable creating the session variables below when they log in
session_start();
// Force script errors and warnings to show on page in case php.ini file is set to not display them
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
//-----------------------------------------------------------------------------------------------------------------------------------
// Initialize some vars


include 'connect_to_mysql.php';


    $var_error="";  
    if (isset($_SESSION['error'])) {

         $var_error = $_SESSION['error'];
        unset($_SESSION['error']);
        $error_check_tok = "error_overlay();";

    }else{
            unset($_SESSION['error']);

    }




$login_username = '';
$login_password = '';
if (isset($_POST['login_submit'])) {

    $login_username = $_POST['login_username'];
    $login_password = $_POST['login_password'];

    $login_username = stripslashes($login_username);
    $login_password = stripslashes($login_password);

    $login_username = strip_tags($login_username);
    $login_password = strip_tags($login_password);



    // error handling conditional checks go here
    if ((!$login_username) || (!$login_password)) { 

       $reg_error = "you did not enter both Username and Password, Please try again.";
       $_SESSION['error'] = $reg_error;
       header("Location: index.php");

    } else { // Error handling is complete so process the info if no errors
        include 'connect_to_mysql.php'; // Connect to the database

        $login_username = mysql_real_escape_string($login_username); // After we connect, we secure the string before adding to query
        $login_password = mysql_real_escape_string($login_password); // After we connect, we secure the string before adding to query

        $login_password = md5($login_password); // Add MD5 Hash to the password variable they supplied after filtering it
        var_dump($login_username);
        var_dump($login_password);
        // Make the SQL query
        $sql_users = mysql_query("SELECT * FROM users WHERE username='$login_username' AND password='$login_password' AND account_activated='1'", $general); 
        $login_check = mysql_num_rows($sql_users);
        // If login check number is greater than 0 (meaning they do exist and are activated)
        if($login_check >= 1){ 
                while($row_users = mysql_fetch_array($sql_users)){

                    // Pleae note: Adam removed all of the session_register() functions cuz they were deprecated and
                    // he made the scripts to where they operate universally the same on all modern PHP versions(PHP 4.0  thru 5.3+)
                    // Create session var for their raw id
                    $user_id = $row_users["user_id"];   
                    $user_no_of_logins = $row_users["no_of_logins"];
                    $user_online = $row_users["online"];

                    $_SESSION['user_id'] = $user_id;
                    // Create the idx session var
                    $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id");
                    // Create session var for their username
                    $login_username = $row["login_username"];
                    $_SESSION['login_username'] = $login_username;
                    // Create session var for their password
                    $login_userpass = $row["login_password"];
                    $_SESSION['login_userpass'] = $login_userpass;


                    //$sql_login_check = mysql_num_rows($sql_login);
                    if($user_no_of_logins == "0"){

                        mysql_query("UPDATE users SET first_login=now() WHERE user_id='$user_id' LIMIT 1", $general);

                    }

                    if($user_online == "0"){

                       mysql_query("UPDATE users SET online = '1' WHERE user_id='$user_id' LIMIT 1", $general); 
                       mysql_query("UPDATE system SET no_online = no_online + 1", $system);
                    }


                    mysql_query("UPDATE users SET last_login=now() WHERE user_id='$user_id' LIMIT 1", $general);  
                    mysql_query("UPDATE users SET no_of_logins = no_of_logins + 1 WHERE user_id='$user_id' LIMIT 1", $general); 
                    mysql_query("UPDATE system SET total_logins = total_logins + 1", $system);




                } // close while

                // Remember Me Section
                if(isset($_POST['login_remember'])) { 
                     $encryptedID = base64_encode("g4enm2c0c4y3dn3727553$user_id");
                     setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days
                     setcookie("passCookie", $login_password, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days

                }

                // All good they are logged in, send them to homepage then exit script
                header("Location: overview.php");

        } else { // Run this code if login_check is equal to 0 meaning they do not exist
            $reg_error = "Login Inputs Incorrect, Please try again.";
            $_SESSION['error'] = $reg_error;
            header("Location: index.php");
        }


    } // Close else after error checks

} 

?>
4

2 回答 2

2

嗯,它就在那里:

<blink>
           vvvvvvvvvvvvvvvvvvvvvvvvvv
---------> var_dump($login_username); <---------
---------> var_dump($login_password); <---------
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
                                        </blink>

这没有出现在另一个系统上的原因很可能是输出在该系统上被缓冲。在新系统上,输出没有缓冲,所以上面是输出,而你的重定向标头不是。为什么会这样,请阅读https://stackoverflow.com/a/8028987/476

于 2012-10-03T01:57:31.337 回答
0

“它只是在顶部显示用户名和密码,就好像我是他们的 var_dump 一样。”

这是因为您正在调用var_dump用户名和密码。

从您的代码中删除以下内容将阻止它转储用户名和密码。

var_dump($login_username);
var_dump($login_password);
于 2012-10-03T01:59:11.540 回答