Hello guys,

I've been trying to get a item database website going for lineage 2. It runs, but spews out some errors. Any help would be greatly appreciated. 🙂

Thanks in advance!

Notice: Undefined index: page in .../index.php on line 21
Notice: Undefined index: lang in .../index.php on line 25
Notice: Undefined index: lang in .../index.php on line 31
Notice: Undefined index: npc_id in .../index.php on line 91
Notice: Undefined index: action in .../index.php on line 93

<?php
/***************************************************************************
 *                                L2 Mobfinder
 *                            --------------------
 *   begin                : Wednesdey, Jun 20, 2006
 *   copyright            : (C) 2006 Anubis <anubis@gods.de>
 *
 ***************************************************************************/

//ob_start( 'ob_gzhandler' );

define( 'DEBUG_MODE', false );

require_once( 'includes/config.php' );

ini_set( 'session.use_cookies', '1' );
ini_set( 'session.use_only_cookies', '1' );
ini_set( 'session.name', 'Mobfinder' );
session_start();

$_GET['page'] = intval($_GET['page']);
$pid = ( $_GET['page'] > 0 && $_GET['page'] <= 6 ) ? $_GET['page'] : 1;

// include language-files
if( $_GET['lang'] == 'de' )
{
	$_SESSION['language'] = 'german';
	header('Location: ' . DOMAIN_NAME . 'index.php?page='.$pid );
	exit;
}
else if( $_GET['lang'] == 'en' )
{
	$_SESSION['language'] = 'english';
	header('Location: ' . DOMAIN_NAME . 'index.php?page='.$pid );
	exit;
}
if( $_SESSION['language'] != 'english' && $_SESSION['language'] != 'german' )
	$_SESSION['language'] = DEFAULT_LANGUAGE;
require_once( 'language/' . $_SESSION['language'] . '/lang_main.php' );

require_once( 'includes/dbAccess.class.php' );
$dbc = new dbAccess();
require_once( 'includes/dbFunctions.php' );
update_Stats( 'total_views' );

require_once('includes/functions.inc.php' );
$start_time = start_time();


$template_name = DEFAULT_TEMPLATE;
$current_template_path = 'templates/' . $template_name . '/';
include_once( 'includes/template.php' );
$tpl = new Template( $current_template_path );


// Link-Konfiguration
define( 'PAGE_NPCMOBS',		 1 );
define( 'PAGE_ITEMS',		 2 );
define( 'PAGE_ARMORS',		 3 );
define( 'PAGE_WEAPONS',		 4 );
define( 'PAGE_SHOPS',		 5 );
define( 'PAGE_RECIPES',		 6 );
$pages = array(
	PAGE_NPCMOBS => array( 'LINKNAME' => $lang['NAVI_NPCMOBS'],
				'LINKURL'  => 'index.php?page=1',
				'FILENAME' => 'content_listnpc.php'),
	PAGE_ITEMS => array( 'LINKNAME' => $lang['NAVI_ITEMS'],
				'LINKURL'  => 'index.php?page=2',
				'FILENAME' => 'content_listitem.php'),
	PAGE_ARMORS => array( 'LINKNAME' => $lang['NAVI_ARMORS'],
				'LINKURL'  => 'index.php?page=3',
				'FILENAME' => 'content_listitem.php'),
	PAGE_WEAPONS => array( 'LINKNAME' => $lang['NAVI_WEAPONS'],
				'LINKURL'  => 'index.php?page=4',
				'FILENAME' => 'content_listitem.php'),
	PAGE_SHOPS => array( 'LINKNAME' => $lang['NAVI_SHOPS'],
				'LINKURL'  => 'index.php?page=5',
				'FILENAME' => 'content_listshop.php'),
	PAGE_RECIPES => array( 'LINKNAME' => $lang['NAVI_RECIPES'],
				'LINKURL'  => 'index.php?page=6',
				'FILENAME' => 'content_listitem.php')
);


// Page-Header START -------------------------------------------------------
include_once( 'includes/content_header.php' );
// Page-Header END ---------------------------------------------------------


// Page-Content START -------------------------------------------------------
if( $_GET['npc_id'] > 0 && $_GET['action'] == 'droplist' )
	include_once( 'includes/content_listdrop.php' );
else if( $_GET['action'] == 'showmap' && $_GET['npc_id'] > 0 )
	include_once( 'includes/content_drawmap.php' );
else
	include_once( 'includes/'. $pages[$pid]['FILENAME'] );
// Page-Content END ---------------------------------------------------------


// Page-Footer START -------------------------------------------------------
include_once( 'includes/content_footer.php' );
// Page-Footer END ---------------------------------------------------------


//ob_end_flush();

?>

    Your problem is that you're referencing external variables (e.g. those in $_GET) without first verifying whether or not they actually exist (which apparently they don't, according to the error messages). You should use [man]isset/man or [man]empty/man to do this.

    For example, code like this:

    if($_POST['submit']) {

    is, IMHO, a bit sloppy and should instead be written as:

    if(isset($_POST['submit'])) {

      Brad is of course pointing out the correct course of action. However, many PHP scripts have been written that make reference to a $_GET var which may or may not be defined. Although this can be risky in some cases, in many cases it doesn't present any significant risk.

      If you are sure that referencing these undefined vars will not introduce any particular security risk, you might consider changing this line:

      define( 'DEBUG_MODE', false ); 
      

      to this:

      define( 'DEBUG_MODE', false ); 
      if (!DEBUG_MODE) {
        error_reporting(E_ALL  & ~E_NOTICE);
      }
      

      That tells PHP to hide the notices you are getting if DEBUG_MODE is false.

      You should read this for more info:
      http://us2.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

        Thanks for the help guys, I fixed it. 🙂

          Write a Reply...