I am new to coding and new to Bootstrap. I'm encountering a problem with the Bootstrap Navbar, all goes well until I try to use consecutive IF statements that check the Session and show or don't show specific menu items.
I have a function drawTopMenu()
PHP function that I include on most pages. This header is using YUI and I'm changing it to Bootstrap. Here is the first part of the code that is not giving any issues. This is a test file as I was having lots of trouble trying to figure out the cause.
I have tried to remove the IF statements and this solves the "HTTP 500 server error", but I do need to show specific items to specific users. I also tried reverting back to the YUI menu bar cade and that works fine with many more IF statements.
EDIT:
- I have replaced the code from within the
IF {}
by "...", this did certainly not cause the issue. It's the IF statements and as soon as I add the extra IF statement the code breaks. Even if myprimaryGroupId = 2
, and the 3rd IF should be skipped. - I have changed the Bootstrap version from 4.0.0 to 5.0.2 and changed the code accordingly but the issues with the IF statement remain.
- Also, the server is using php 5.6.40, I do want to go to the latest version here too.
The code now looks like this "//BREAKS THE CODE" is the IF statement causing problems:
function drawTopMenu () {
$session_int = $_SESSION['primaryGroupId'];
//Bootsrap menubar
$html = <<<EOS
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/home.php">
<img src="http://192.168.42.30:8080/lqcadjust/logo-grey.png" alt="Home" width="153" height="34"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
EOS;
//Approval List
if (($session_int == 1) || ($session_int == 2)) {
$html .= <<<EOS
<li class="nav-item"><a class="nav-link" href="/home/event/approval_status.php">Approval List</a></li>
EOS;
}
//File Maintenance
if (($session_int == 1) || ($session_int == 2)) {
...
}
if (($session_int == 2)){
...
}
//BREAKS THE CODE
if (($session_int == 3)){
...
}
//BREAKS THE CODE
}