【发布时间】:2014-08-26 02:30:41
【问题描述】:
我在一个页面上遇到了一个非常奇怪的问题(它似乎没有发生在其他任何地方)。
当我通过直接输入将页面源复制并粘贴到验证器中时,它是有效的。
但是当使用 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-->
【问题讨论】:
-
session_start();加载了吗?如果你没有它,它是必需的。 -
是的。我也有错误报告。
-
完整代码,就像所有东西一样?这有点多,我认为没有人真的想筛选所有内容(特别是因为其中大部分与问题无关)。但是,我会从错误开始的地方提出所有内容。
标签: php validation html-validation