Reputation: 27
I'm having a really weird issue with one page (it doesn't seem to be happening anywhere else).
When I copy and paste the page source by direct input into the validator, it's valid.
But when using the URI it gives all kinds of errors because its source seems to have two lines above my doctype saying:
<!DOCTYPE html><br />
<b>Notice</b>: Undefined index: user_id in <b>[path]</b> on line <b>11</b><br />
Line 11 is
$userid = $_SESSION['user_id'];
When I print_r($_SESSION);
user_id is there and it's correct.
Where is the validator getting these errors from and what can I do to fix it?
EDIT: Here's the code from before that
<?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');
?>
And here's 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);
}
And here's 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-->
Upvotes: 0
Views: 146
Reputation: 74217
You have $userid = (int) $_SESSION['user_id'];
in header.inc.php
and then you're redeclaring it in $userid = $_SESSION['user_id']; //Line 11
Either remove it, or set a different conditional statement for it, since it's already declared in the other file.
Upvotes: 1