Trying to get my PHP navigation bar to work. I am trying to echo the page where the user is on with the attached class of active if the page is current.
Here is my code
"Home",
"pages/contact.php" => "Contact Us",
"pages/services.php" => "services",
"pages/employees.php" => "Employees",
"pages/dashboard.php" => "Dashboard");
$cururl = $_SERVER['PHP_SELF'];
foreach ($pages as $url => $label) {
echo '- ', "$label", '
';
}
?>
This should work for you. Because, you were trying to access the url address using GET-METHOD
. Here, I have fetched your url by doing $cururl = $_SERVER['PHP_SELF'];
and checked for the active menu item as if (strpos($cururl,$url)!==false)