简体   繁体   English

升级到PHP 5.5.12(WAMP 2.5)后,未定义索引“ admin”

[英]Undefined Index “admin” After Upgrading to PHP 5.5.12 (WAMP 2.5)

I got the following error after upgrading to PHP 5.5.12 (WAMP 2.5): 升级到PHP 5.5.12(WAMP 2.5)后出现以下错误:

Notice: Undefined index: admin in C:\\wamp\\www\\MyWebsite\\check.php on line 83 注意:未定义的索引:第83行的C:\\ wamp \\ www \\ MyWebsite \\ check.php中的admin

The code in the " index.php ": index.php ”中的代码:

<?php
include_once("connect.php");
include_once "check.php";
echo "You are logged in."
?>

The code in the " check.php ": check.php ”中的代码:

<?php
session_start();
include_once("connect.php");

$error_msg = "";

if (isset($_POST['username']))
{
    include_once("connect.php");

    $username = $_POST['username'];
    $password = $_POST['password'];

    $username = preg_replace('#[^a-z 0-9?!]#i', '', $username);
    $username = strip_tags($username);
    $username = $mysqli->real_escape_string($username);
    $username = preg_replace("#`#i", "", $username);

    $password = preg_replace('#[^a-z 0-9?!]#i', '', $password);
    $password = strip_tags($password);
    $password = $mysqli->real_escape_string($password);
    $password = preg_replace("#`#i", "", $password);

    if($result = $mysqli->query("SELECT * FROM password"))
    {
        while($row = $result->fetch_array())
        { 
            $admin =  $row["username"];
            $adminpass =  $row["password"];

        }
    }

    if (($username != $admin) || ($password != $adminpass))
    {
        $error_msg = ': <font color="#FF0000">Your login information is incorrect</font>';
    }
    else
    {
        //session_register('admin'); // deprecated as of PHP 5.3.0
        session_start();
        $_SESSION['admin'] = $username;
        require_once "index.php";
        exit();
    }
}

if($result = $mysqli->query("SELECT * FROM password"))
{
    while($row = $result->fetch_array())
    { 
        $admin =  $row["username"];
        $adminpass =  $row["password"];

    }
}

if ($_SESSION['admin'] != $admin)
{
    echo '
    <h3>Only the administrator can view this directory</h3><br />

    <table width="340" border="0">
        <form action="check.php" method="post" target="_self">
              <tr>
                <td colspan="2">Please Log In Here' . $error_msg . '</td>
              </tr>
              <tr>
                <td width="96">Username:</td>
                <td width="234"><input type="text" name="username" id="username" style="width:98%" /></td>
              </tr>
              <tr>
                <td>Password:</td>
                <td><input type="password" name="password" id="password" style="width:98%" /></td>
              </tr>
              <tr>
                <td colspan="2" align="center"><input type="submit" name="button" id="button" value="Log In Now" /></td>
              </tr>
        </form> 
    </table>

    <br /><br /><br />
    ';

    exit();
}
?>

Usually I used " session_register() " to register the " admin " session variable, which worked well in PHP 5.1. 通常,我使用“ session_register() ”来注册“ admin ”会话变量,在PHP 5.1中效果很好。 But now in PHP 5.5 I got the " Undefined index: admin " error message. 但是现在在PHP 5.5中,我收到了“ Undefined index:admin ”错误消息。

How can I fix this issue? 如何解决此问题?

Check that $_SESSION['admin'] is null 检查$_SESSION['admin']是否为空

like this 像这样

if (!isset($_SESSION['admin']) || $_SESSION['admin'] != $admin)
{
    echo '
    <h3>Only the administrator can view this directory</h3><br />';
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:使用 wamp php 5.5.12 调用未定义的函数 sqlsrv_connect() - Fatal error: Call to undefined function sqlsrv_connect() using wamp php 5.5.12 无法在WampServer 2.5上使用PHP5.5.12上传音频文件 - Can't upload audio file with PHP5.5.12 on WampServer 2.5 WAMP和PHP中未定义的索引错误报告 - Undefined Index Error Reporting in WAMP and PHP 重新安装WAMP后,PHP我的管理员无法正常工作 - PHP my admin not working after reinstalled WAMP 将PHP从5.3.4升级到5.3.22后,PHP CURL未在WAMP中加载 - PHP CURL not loading in WAMP after upgrading PHP from 5.3.4 to 5.3.22 无法加载动态库 &#39;c:/wamp/bin/php/php5.5.12/ext/php_intl.dll&#39; - Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_intl.dll' 哪里可以找到适用于Windows wampserver 2.5的php 5.5.12的php_imagick.dll? - Where to find php_imagick.dll for php 5.5.12 for Windows wampserver 2.5? 升级到PHP 5.4.0后调用未定义的方法 - Call to undefined method after upgrading to PHP 5.4.0 未定义索引:在第 4 行输入 C:\\wamp\\www\\submit.php - Undefined index: type in C:\wamp\www\submit.php on line 4 未定义索引:第 4 行 C:\wamp\www\emailvalidate.php 中的电子邮件 - Undefined index: email in C:\wamp\www\emailvalidate.php on line 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM