PHP Menu query

A

Anonymous

Guest
Hi,

I’d just like to please, enquire if php coding has been changed which is stopping my menu from displaying properly?


I've created a landing page which currently has a login and sign up form. Both of theses work fine independently as I wanted them to. Anyway.

I’m now experiencing difficulty with the top menu. Idea been:-
1. If a user is just visiting, then display a Join Us button and a Sign In button.
2. If a user is already signed in, and they return to the landing page, then display a Dashboard Button and Sign Out button.
I’ve created this using php, however when I load the landing page I’m getting the php code been displayed as well as the buttons, instead of the buttons only.

Code:
<?
            if(session_status() !== PHP_SESSION_ACTIVE) {
                session_start();
            }

            //Navigation
            if ($_SESSION['member_id' != "") {
                echo "<nav class='navbar navbar-light bg-light static-top'>";
                    echo "<div class='container'>";
                        echo "<a class='navbar-brand' href='/welcome.php'>". $_SESSION['settings_title'] . "</a>";
                        echo "<a class='btn btn-primary' href='/Members/user/dashboard.php'>Dashboard</a>";
                        echo "<a class='btn btn-info' href='/Guest/signin/test.php'>Test</a>";
                    echo "</div>";
                echo "</nav>";
            } else {
                echo "<nav class='navbar navbar-light bg-light static-top'>";
                    echo "<div class='container'>";
                        echo "<a class='navbar-brand' href='/welcome.php'>". $_SESSION['settings_title'] . "</a>";
                        echo "<a class='btn btn-primary' href='/Members/user/dashboard.php'>Sign In</a>";
                        echo "<a class='btn btn-info' href='/Guest/signin/test.php'>Test</a>";
                    echo "</div>";
                echo "</nav>";
            }
        ?>

Or would there be a better way of creating the menu, or create both of the menu in html, and getting the php code to load whichever menu is required?

Thank You very much.
 
I’d just like to please, enquire if php coding has been changed which is stopping my menu from displaying properly?
Short answer - No

Long answer - No:

PHP has no direct affect on how things are displayed.

Your use of PHP may create an output which may not be as desired.

PHP responds to requests, we would normally (but not exclusively) respond to those requests by returning HTML. What and how that is used is not up to PHP and moreover, it does not care what happens to it. It is up to the coder to return the correct and expected response (e.g. a well formed HTML page)


If your menu has "suddenly stopped working" then you must of made a change somewhere, so trace back what you have changed so that you can correct it.
 
Once you get you menu working correctly, it sounds like you only want to show menu options to people who have the right security level (logged in for example).

for example

Code:
if (isset($_SESSION['member_id'])) {
  echo "<a class='btn btn-primary' href='/Members/user/dashboard.php'>Dashboard</a>";
}

though I would do more than just checking if the user is logged in or not to access the member only menus. Maybe a security level?
 
Back
Top