Forum Moderators: coopster
I am processing PHP sessions through a specific page called login_check.php. This page checks to make sure the user is logged in. If the user is logged in, it keeps the session open, but if not logged in, it deletes the session.
Then, I have a page called header_main.php. This page is a dynamic header which I include in all of my pages. In this page, I include the login_check.php page in order to display the user's login status in the header of my pages.
My problem is that, in order to process the sessions through my header_main.php page, I would have to include my header with the full document root, which looks like this:
include($_SERVER["DOCUMENT_ROOT"] . '/layout/header_main.php');
Because this will not correctly process the sessions:
include('http://domain.com/layout/header_main.php');
This would be fine if I left it like this, however, I also need to pass variables through my header_main.php page, which would look something like this using the working method:
include($_SERVER["DOCUMENT_ROOT"] . '/layout/header_main.php?home=true&p=h&error=1');
These variables control the page navigation styles for different pages and display specified error messages for certain errors. However, this include function will display an error because it is trying to find a page called "header_main.php?home=true&p=h&error=1" which does not exist.
So now for the question, is there any way that I can successfully process sessions through my header but still attach variables on my page address to include my header on all my pages?
Is so then cant you rewrite those functions to take values input directly?
i.e.
function OLD_nav() {
if ($_GET[home] == true) {
// echo's nav bar highlighting home
}
}
function NEW_NON_GET_nav($home = 1) {
if ($home == 1) {
// echo's nav bar highlighting home
}
}
include($_SERVER["DOCUMENT_ROOT"] . '/layout/header_main.php');
echo NEW_NON_GET_nav(1); // or even just echo NEW_NON_GET_nav();
// or if not home then -
echo NEW_NON_GET_nav(0)
Assuming you want to highlight the current section on the menu:
You can set a variable called $current and set it to the section like so:
$current = 'home' or $current = 'news' or whatever
and then use a switch statement to highlight the section.
This gives me complete flexibility to choose the section to be highlighted.