Warning: Undefined array key "uid" in C:xampphtdocswwwheader.php and Fatal error

  php, smarty

I am beginner to php, and my job task is to take over a program created by another programmer company. The thing is, the outsource company didn’t even provide any training and expected me to be a genius to read codes and fixed it by myself. There is not even guidance how to deploy the system . Anyway, i managed to forced my boss to give me a session with the programmer and managed to get 2 hours zoom session tomorrow, which i know is not enough.

Okay, so, I am trying to run the system which is a web based in xampp, local host, but i encounter error like this, and this system used smarty which I also am still learning.

I know some of the solution recommended is to use isset() function, but do i need to create each isset() function to all the lines? I am really new in this.

Warning:
Warning: Undefined array key "uid" in C:xampphtdocswwwheader.php on line 164

Warning: Undefined array key "username" in C:xampphtdocswwwheader.php on line 165

Warning: Undefined array key "name" in C:xampphtdocswwwheader.php on line 166

Warning: Undefined array key "role" in C:xampphtdocswwwheader.php on line 167

Warning: Undefined array key "starttime" in C:xampphtdocswwwheader.php on line 173

Warning: Undefined array key "expirytime" in C:xampphtdocswwwheader.php on line 174

Warning: Undefined array key "starttime" in C:xampphtdocswwwheader.php on line 176

Warning: Undefined array key "expirytime" in C:xampphtdocswwwheader.php on line 177

Warning: Undefined array key "starttime" in C:xampphtdocswwwheader.php on line 179

Warning: Undefined array key "expirytime" in C:xampphtdocswwwheader.php on line 180

Warning: Undefined array key "expirytime" in C:xampphtdocswwwheader.php on line 183
Fatal error: Uncaught Error: Undefined constant "DB_FETCHMODE_ASSOC" in C:xampphtdocswwwlibsmysql.php:325 Stack trace: #0 C:xampphtdocswwwlibsdaoUsersDao.class.php(91): Database->fetchAssocArrBySql(‘SELECT count(*)…’) #1 C:xampphtdocswwwlibsdaoUsersDao.class.php(9): UsersDao::tableExist() #2 C:xampphtdocswwwmodeltracking.mod.php(4): UsersDao::createTableIfNotExist() #3 C:xampphtdocswwwindex.php(19): require(‘C:xampphtdocs…’) #4 {main} thrown in C:xampphtdocswwwlibsmysql.php on line 325

The codes from header.php

  <?php

$website_root = dirname(__FILE__)."/";

//ini_set('memory_limit', '1024M'); // or you could use 1G
//ini_set('max_execution_time', 600); //600 seconds = 10 minutes

date_default_timezone_set("Asia/Kuala_Lumpur");

// server should keep session data for AT LEAST 4 hour
ini_set('session.gc_maxlifetime', 14400);   // 14400sec = 4 hours (60 x 60 x 4)
//ini_set('session.gc_maxlifetime', 3600);  // 3600sec = 1 hour (60 x 60)
//ini_set('session.gc_maxlifetime', 60);        // 60sec = 1 min

// each client should remember their session id for EXACTLY 5 hours
session_set_cookie_params(14400);
//session_set_cookie_params(3600);
//session_set_cookie_params(1800);
session_start();

require($website_root."config.php");
require($website_root.'libs/MyFunction.class.php');
require($website_root.'libs/APIFunction.class.php');
require($website_root.'libs/DBAPIFunction.class.php');
require($website_root.'libs/Smarty.class.php');
require($website_root.'libs/mysql.php');
// require ($website_root.'libs/email.class.php');
// require ($website_root.'libs/mail/PHPMailerAutoload.php');
require($website_root.'libs/Uploader.class.php');
require($website_root.'libs/KLogger.php');

$dbF=new DBAPIFunction();

$apiF=new APIFunction();

$lanarr = MyFunction::getFile("lan");
$tpl = new Smarty;

$db = new Database($cfg_db_host,$cfg_db_username,$cfg_db_password,$cfg_db_dbname);
$log = new KLogger ( $website_root.'logs/'.date('Y_m_d', time()).'.log', KLogger::DEBUG );

$id = isset($_GET['id']) ? $_GET['id'] : ''; //initalised the id for problem undefined key "id"
//$id = $_REQUEST["id"];
$code = isset($_GET['code']) ? $_GET['code']: '';
//$code = $_REQUEST["code"]; (original code)

$tpl->assign("id", $id);
$tpl->assign("code", $code);

unset($cfg_db_host);
unset($cfg_db_username);
unset($cfg_db_password);
//unset($cfg_db_dbname);

$mod = $_REQUEST['mod'];
$ac = isset($_GET['action']) ? $_GET['action']: '';
//$ac = $_REQUEST['action'];
$srv = isset($_GET['srv']) ? $_GET['srv']: '';
//$srv=$_REQUEST['srv'];

$tpl->assign("ac", $ac);

if ($mod=="admin") {
    foreach ($lanarr as $key => $value) {
        if($_COOKIE['lanA'] == $value)
        {
            $language = $value;
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lanA;
} else if ($mod=="client") {
    foreach ($lanarr as $key => $value) {
        if($_COOKIE['lanA'] == $value)
        {
            $language = $value;
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lanA;
} else if ($mod=="tracking") {
    foreach ($lanarr as $key => $value) {
        
        if(isset($_GET['lanA'])){
        $lanA = $_GET['lanA'];
        
        if($_COOKIE['lanA'] == $value)
        {
            $language = $value;
        }
        
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lanA;
}else if ($mod=="admina") {
    foreach ($lanarr as $key => $value) {
        if($_COOKIE['lanA'] == $value)
        {
            $language = $value;
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lanA;
}else if ($mod=="custcare") {
    foreach ($lanarr as $key => $value) {
        if($_COOKIE['lanC'] == $value)
        {
            $language = $value;
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lanC;
}else if ($mod=="inventory") {
    foreach ($lanarr as $key => $value) {
        if($_COOKIE['lanA'] == $value)
        {
            $language = $value;
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lanA;
}else if($mod=="develop"){
    foreach ($lanarr as $key => $value) {
        if($_COOKIE['lanD'] == $value)
        {
            $language = $value;
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lanD;
}else{
    
    // redirect to Admin Page
    header("location: ?mod=tracking");

    foreach ($lanarr as $key => $value) {
        if($_COOKIE['lan'] == $value)
        {
            $language = $value;
        }
    }
    require($website_root."lan/".$language.".php");
    $lan=$lan;

}

//$smarty->force_compile = true;
$tpl->debugging = false;
//$tpl->caching = true;
//$tpl->cache_lifetime = 120;
$tpl->assign("lan",$lan,true);
$tpl_dir=$cfg_tpl_dir.$templates;
$tpl->assign("tpl_dir",$tpl_dir);
if ($mod) {
    $tpl->assign("templates",$templates.$mod."/");
}else{
    $tpl->assign("templates",$templates."index/");
}
$tpl->assign("API_INC",'API_INC'); //undefined constant "API_INC"
$tpl->assign("API_VER",API_VER);
$tpl->assign("API_KEY",API_KEY);

$tpl = isset($_GET['uid']) ? $_GET['uid'] : '';
$tpl->assign("uid",$_SESSION['uid']);

$tpl->assign("username",$_SESSION['username']);
$tpl->assign("name",$_SESSION['name']);
$tpl->assign("role",$_SESSION['role']);

$maxlifetime = ini_get("session.gc_maxlifetime");

$tpl->assign("maxlifetime", $maxlifetime);

$tpl->assign("startdatetime", date("Y-m-d H:i:s", $_SESSION["starttime"]));
$tpl->assign("expirydatetime", date("Y-m-d H:i:s", $_SESSION["expirytime"]));

$tpl->assign("startdate", date("Y-m-d", $_SESSION["starttime"]));
$tpl->assign("expirydate", date("Y-m-d", $_SESSION["expirytime"]));

$tpl->assign("starttime", $_SESSION["starttime"]);
$tpl->assign("expirytime", $_SESSION["expirytime"]);
$tpl->assign("timenow", time());

$timeleft = $_SESSION["expirytime"] - time();

$hoursleft = floor($timeleft / 3600);
$minleft = floor($timeleft / 60);
$secleft = $timeleft - ($hoursleft * 3600) - ($minleft * 60);

$tpl->assign("hoursleft", $hoursleft);
$tpl->assign("minleft", $minleft);
$tpl->assign("secleft", $secleft);
$tpl->assign("timeleft", $timeleft);

$tpl->assign("hourpad", str_pad($hoursleft, 2, '0'));
$tpl->assign("minpad", str_pad($minleft, 2, '0'));
$tpl->assign("secpad", str_pad($secleft, 2, '0'));
?>

Really appreciate if you can guides me.

Source: Ask PHP

LEAVE A COMMENT