HTML Validator显示PHP未显示的PHP错误

时间:2014-08-26 02:30:42

标签: php validation html-validation

我在一个页面上遇到了一个非常奇怪的问题(它似乎没有发生在其他任何地方)。

当我通过直接输入将页面源复制并粘贴到验证器中时,它是有效的。

但是当使用URI时,它会出现各种错误,因为它的源代码似乎比我的doctype高出两行:

<!DOCTYPE html><br />
<b>Notice</b>: Undefined index: user_id in <b>[path]</b> on line <b>11</b><br />

第11行

$userid = $_SESSION['user_id'];

当我print_r($_SESSION); user_id在那里并且它是正确的时候。

验证者从哪里获取这些错误,我该怎么做才能解决它?

编辑:这是之前的代码

<?php
    if(!isset($filepath)){
        $filepath = '../';
    }

    $lastseen = 'chatting away on the forums';
    include($filepath . 'includes/header.inc.php');

    print_r($_SESSION); //this displays Array ( [user_id] => 39 [name] => theatre [staff] => officer [logintime] => 8:46pm [upgrade] => undead ) exactly as it should

    $userid = $_SESSION['user_id']; //Line 11

if(isset($_GET['id']) && is_numeric($_GET['id']) && ($_GET['id'] > 0)){
    $boardid = (int) $_GET['id'];
}

/* Validate form submission */
if(($_SERVER['REQUEST_METHOD'] == 'POST') && ($_SERVER['HTTP_HOST'] == 'zombiesim.net') && isset($_POST['postcheck']) && ($_POST['postcheck'] == 'yes')){
    //a bunch of other form validation type stuff, but it doesn't even get here
    }
    ?>
    <!doctype html>
    <html dir="ltr" lang="en-US">
    <head>
    <meta charset="utf-8" />
    <!-- other meta tags, title, and link tags here -->
    <?php
    include($filepath . 'includes/pagehead.inc.php');
    ?>

这里是header.inc.php

    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);

    /* Start sessions and output buffering */
    session_start();
    ob_start();

    /* Include Functions */
include_once($filepath . 'includes/functions.inc.php');

/* Definte Referrer URL for Form Validation */
DEFINE('LASTURL', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);

/* If logged in, update last seen */
if(isset($_SESSION['user_id']) && is_numeric($_SESSION['user_id'])){
    $userid = (int) $_SESSION['user_id'];
    include($filepath . 'dbupdate.inc.php');
    $now = time();
    $now = date("Y-m-d H:i:s", $now);
    $seenq = "UPDATE users SET lastseen='" . $now . "', lastseenat='" . $lastseen . "' WHERE user_id=$userid";
    $seenr = mysqli_query($dbupdate, $seenq);
}

这是pagehead.inc.php

<!-- Javascript for Google Analytics tracking -->
<script type="text/javascript" src="<?php echo $filepath; ?>js/analytics.js"></script>
</head>

<body>
<!--then begins the navigation and ends with the opening div for the main content-->

1 个答案:

答案 0 :(得分:1)

$userid = (int) $_SESSION['user_id'];中有header.inc.php,然后您在$userid = $_SESSION['user_id']; //Line 11

中重新声明了{{1}}

删除它,或为它设置不同的条件语句,因为它已在其他文件中声明。