Jump to content
Larry Ullman's Book Forums

Help With The Header File.


Recommended Posts

Hi,

I am not sure if I understand this right, if I want to use the same template you're using in the book, then the header page completly changes from the code in the download to the code in the book?

 

Here is the code that I put from the book, but it gives me error when I view the site.

 

<!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 wasn't provided...
 if (isset($page_title)) {
   echo $page_title;
 } else {
   echo 'Virtual Script';
 }
 ?></title>

    <!-- 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>
<?php
   // <!-- Wrap all page content here -->
  

       $page = array (
          'Home' => 'index.php',
          'About' => 'about.php',
          'Contact' => 'contact.php',
          'Register' => 'register.php'
          );
         

      $this_page = basename($_SERVER['PHP_SELF']);
      foreach ($page as $k => $v)  {
           echo '<li';
      if ($this_page = $v) echo ' class="active"';

      echo '><a href="' . $v . '">' . $k . '</a></li>';
} // END OF FOREACH LOOP.

if (isset($_SESSION['user_id'])) {

             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>';
}

             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>';
         }

?>

          
<?php
$q = 'SELECT * FROM categories ORDER BY categories';
$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="' . $category . '">' . htmlspecialchars($category) . '</a>';
     }
 ?>   
 
<?php
if (!isset($_SESSION['user_id'])) {
require('includes/login_form.inc.php');
}
?>     

<div class="col-9">
<!-- CONTENT -->

</html>

 

 

Thanks very much.

 

 

 

Link to comment
Share on other sites

Hi,

I fixed the error but the page layout is gone, so I had to reupload the header file, I am trying to get the same template as shown in the book but I can't get rid of the drobdown top menu to make the links appear at the top.
 

Thanks

Link to comment
Share on other sites

 Share

×
×
  • Create New...