未定义的索引

时间:2013-07-23 08:44:42

标签: php session undefined

注意:未定义的索引:第5行的C:\ wamp \ www \ CodeCanyon \ MCBuddy \ Global.php中的用户名  注意:未定义的索引:第6行的C:\ wamp \ www \ CodeCanyon \ MCBuddy \ Global.php中的密码

这是我的 Global.php 代码:

session_id();
session_start();
ob_start();
$loggedIn = $_SESSION['Username'];
$Password = $_SESSION['Password']; 
$CurrentTime = time();
// MySQL Database Conection Information
define("DBHost", "localhost"); // MYSQL Database Host
define("DBUsername", "root"); // MYSQL Database Username
define("DBPassword", ""); // MYSQL Database Password
define("Database", "mcbuddy"); // MYSQL Database Name
// Establish Connection to MYSQL Database
$db = new mysqli(DBHost, DBUsername, DBPassword, Database);
if ($db->connect_errno) {
    echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error;
}

我的 Login.php (我认为错误就在这里)

<?php
require 'Global.php';
?>
<div class='well'>
<div style='text-align:center'>
<h2> Sign In </h2>
<center>
<p id='errorMsg' style='background-color: #D11124; width:300px; color:white; text-align:center;'/>
<form action='' method='POST'>
<input type='text' name='Username' placeholder='Username'> <br />
<input type='password' name='Password' placeholder='Password'> <br />
<input class='btn btn-xlarge' type='submit' name='signin' value='Sign In'> 
</form>
</div>
</div>

<?php
if(isset($_REQUEST['signin'])) {
$Username = htmlspecialchars(strip_tags($_REQUEST['Username']));
$Password = htmlspecialchars(strip_tags($_REQUEST['Password']));
$p1 = md5($Password);
$UserInfo = $db->query("SELECT * FROM users WHERE Username='$Username'");
$UserI = $UserInfo->fetch_array(MYSQLI_BOTH);

    if(empty($Password) || $Password == '') {
    echo "
    <script type='text/javascript'>
                document.getElementById('errorMsg').innerHTML = 'Password is empty!';
    </script>
    ";
    }
    elseif(empty($Username) || $Username == '') {
    echo "
    <script type='text/javascript'>
                document.getElementById('errorMsg').innerHTML = 'Username is empty!';
    </script>
    ";
    }
        elseif($UserI['Password'] != $p1) {
        echo "
        <script type='text/javascript'>
                document.getElementById('errorMsg').innerHTML = 'Incorrect username/password';
        </script>
    ";

       } else {
       $_SESSION['Username']=$Username;
       $_SESSION['Password']=$Password;
       }
}

1 个答案:

答案 0 :(得分:0)

您还可以将会话变量设置为null:

//add line 4:
$_SESSION['Username'] = null;
$_SESSION['Password'] = null;