简体   繁体   中英

PHP header include page not displaying on all pages

Well I'm back with another problem, but hopefully I can get it solved before 11:00pm (pacific time).

So here are the basics. 1) Folder structure is cas225/module7/pht/home, or image, or includes, or tours. 2) My header.inc.html.php is located in the includes folder. 3) Main page (home.html.php) is in the home folder, but the index.php calls it from the pht folder. 4) tours folder has it's one index.php file in there. But its main page, tours.html.php is located in this folder as well.

Now with that in place, my issue is with getting my header.inc.html.php to display on both the main page and the tours page. Currently I can get this to display on my main page, but not the tours page.

This is the code I have in my header.

 <?php define('BASE_URL', '/cas225/module7/pht/'); ?> <header> <img src="<?php echo 'images/portlandhistoricaltoursheader.png'; ?> " alt="Portland Historical Tours" width="920" height="290"> </header> 

Here is the code for displaying this on my home page. Please keep in mind that I also have a nav, and footer include page that work like the header, but they are working at the moment.

 CODE FOR HOME PAGE <?php include 'includes/header.inc.html.php'; ?> CODE FOR THE TOURS PAGE <?php include '../includes/header.inc.html.php'; ?> 

If it's needed, here is the code for the nav & footer.

 <nav> <ul> <li><a href="<?php echo BASE_URL; ?>">Home</a></li> <li><a href="<?php echo BASE_URL; ?>tours">Tours</a></li> <li><a href="<?php echo BASE_URL; ?>reservations">Reservations</a></li> <li><a href="<?php echo BASE_URL; ?>contact">Contact</a></li> </ul> </nav> ----------------- <footer> <div class="footernav"> <a href="<?php echo BASE_URL; ?>">Home</a> <a href="<?php echo BASE_URL; ?>tours">Tours</a> <a href="<?php echo BASE_URL; ?>reservations">Reservations</a> <a href="<?php echo BASE_URL; ?>contact">Contact</a> </div> <p>Copyright &copy; <?php echo date('Y') ?> Portland Historical Tours<br> <a href="mailto:hello@portlandhistoricaltours.com">hello@portlandhistoricaltours.com</a></p> </footer> 

It really depends on how your file structure is set up. Have you tried the following...

<header>
  <img src="/images/portlandhistoricaltoursheader.png" alt="Portland Historical Tours" width="920" height="290">
</header>

or

 <header>
      <img src="http://<?php echo $_SERVER["SERVER_NAME"]; ?>/images/...">
</header>

The other thing to try, being that your pages are all over the place, is to try to use relative paths. try adding ../../ or ../../../ before your image to see if you can locate where the image is on the server based on where your page is that is loading it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM