im trying to deal with error catches and sending the user to a error page upon any errors , im also trying to make sure that the session is started if it is the first and only apperance at the page the user starts at.
from this code, how could i remove the need to try catch every part of the page. i was thinking along the lines of maybe a universal error catch that sends user to an error page upon any error, along with the error data.
So far iv placed every part of the page in try catch , but it seems unecessery. am i right in thinking this, or is alot more secure to check every part of the page this way.
Also the Session_start(); is confusing me, Does it only need to be called once, or should it be called whenever it is not set. if thats the case how do i ensure no matter what page the user begins on , the session will be started. when the session is allready started i cannot recall it on everypage. so how do i check if the session has started or not... Currently i am looking for $_SESSION to have been filled, but that may not be the case on all occassions of every page. im just wondering is there another way to check if Session_Started();
is session started set in the users cache??? so if the user came back to the website and bypassed index.php then session would not need to be started. or should i be checking on evvery page for session to be started?
Any help is greatly appreciated, im new and learning as much as i can but often i come across these instances where only human interaction can advise.
<div class='MainContainerDiv'>
<?php
if (!isset($_SESSION)){session_start();}//session_start should only be called once
try{
$DBConnect='DBmanagment/DBConnect.php';
include $DBConnect;
}
catch(exepetion $e){
$_SESSION['ConnectionError'] = $e->getMessage();
header("location: pages/ERRORS/ERRORPAGE1.php");
exit();die();
};
try{
$selectedpage="pages/landingpage/Landingpage.php";
if (!isset($selectedpage)) {$selectedpage='pages/landingpage/Landingpage.php';} else {$selectedpage=$selectedpage;}
include $selectedpage;
}
catch(exepetion $e){
$_SESSION['ConnectionError'] = $e->getMessage();
header("location: pages/ERRORS/ERRORPAGE1.php");
exit(); die();
};
?>
</div>