Search the Community
Showing results for tags 'example 1'.
-
Question: I have never created a menu system dynamically. I can not figure out how to hide() the register tab if a user is logged in. I am unsure where to start in the header file to do so. Near the bottom of the code is where we decide if we should show the log in page within the index page. I figure I would have to start there, or change the dynamic code to check for this first? I'm such a newbie... LOL Any help, or ideas would be most appreciated. Thank you, The Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <title><?php // Use a default page title if one was not provided... if (isset($page_title)) { echo $page_title; } else { echo 'Knowledge is Power: And It Pays to Know'; } ?></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <!-- Bootstrap core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="css/sticky-footer-navbar.css" rel="stylesheet"> </head> <body> <!-- Wrap all page content here --> <div id="wrap"> <!-- Fixed navbar --> <div class="navbar navbar-fixed-top"> <div class="container"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="index.php">Knowledge is Power</a> <div class="nav-collapse collapse"> <ul class="nav navbar-nav"> <?php // Dynamically create header menus... // Array of labels and pages (without extensions): $pages = array ( 'Home' => 'index.php', 'About' => '#', 'Contact' => '#', 'Register' => 'register.php' ); // The page being viewed: $this_page = basename($_SERVER['PHP_SELF']); // Create each menu item: foreach ($pages as $k => $v) { // Start the item: echo '<li'; // Add the class if it's the current page: if ($this_page == $v) echo ' class="active"'; // Complete the item: echo '><a href="' . $v . '">' . $k . '</a></li> '; } // End of FOREACH loop. // Show the user options: if (isset($_SESSION['user_id'])) { // Show basic user options: // Includes references to some bonus material discussed in Part Four! echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="logout.php">Logout</a></li> <li><a href="renew.php">Renew</a></li> <li><a href="change_password.php">Change Password</a></li> <li><a href="favorites.php">Favorites</a></li> <li><a href="recommendations.php">Recommendations</a></li> </ul> </li>'; // Show admin options, if appropriate: if (isset($_SESSION['user_admin'])) { echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="add_page.php">Add Page</a></li> <li><a href="add_pdf.php">Add PDF</a></li> <li><a href="#">Something else here</a></li> </ul> </li>'; } } // user_id not set. ?> </ul> </div><!--/.nav-collapse --> </div><!--/container--> </div><!--/navbar--> <!-- Begin page content --> <div class="container"> <div class="row"> <div class="col-3"> <h3 class="text-success">Content</h3> <div class="list-group"> <?php // Dynamically generate the content links: $q = 'SELECT * FROM categories ORDER BY category'; $r = mysqli_query($dbc, $q); while (list($id, $category) = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<a href="category.php?id=' . $id . '" class="list-group-item" title="' . $category . '">' . htmlspecialchars($category) . ' </a>'; } ?> <a href="pdfs.php" class="list-group-item" title="PDFs">PDF Guides </a> </div><!--/list-group--> <?php // Should we show the login form? if (!isset($_SESSION['user_id'])) { require('login_form.inc.php'); } //I figure here is where I could add an (isset($_SESSION['user_id']. hide() or something. I can't figure it out. ?> </div><!--/col-3--> <div class="col-9"> <!-- CONTENT --> 0 Quote MultiQuote Edit
- 5 replies
-
- example 1
- registration page
- (and 3 more)