Cannot get my pc built php site to work on the web

149 Views Asked by At

I have part built a php site on my pc. I do not want to have a blog style site, but do want to add a single header, single navbar and single footer to the site, and will start building a login area later. I built it on my PC and it worked wonderfully when displaying it in IE, Chrome, Firefox and Safari, so I copied all the files into a test folder on the existing website, and this didn't work. I got the error message

Fatal error: require(): Failed opening required 'includes/navbar.php'     (include_path='.:/usr/lib/php5.4') 

in /homepages/11/d95668464/htdocs/test/Projects.php on line 54 and haven't a clue what that means.

The required 'includes/header.php and required 'includes/footer.php works correctly and in the right place but the navbar doesn't show at all. The navbar.php code reads:-

<?php

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My Site's Title</title>
<link href="/Styles/Site.css" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1"> 
</head>
<section class="navigation" data-role="navbar">
<nav>
<ul id="menu">
<li><a href="index.php">Home</a></li>
<li><a href="news.php">News &amp; Events</a></li>
<li><a href="projects.php>Projects</a></li. 
<li><a href="contact.php">Contact Us</a></li>
<li><a href="membership.php">Join/Renew</a></li>
<li><a href="links.php">Links</a></li>
</ul>
</nav>
</section>

The code on the page reads:-

 <?php
 include "includes/navbar.php";
 ?>
2

There are 2 best solutions below

1
On BEST ANSWER

Try to link all of your href's to the correct place.

Right now:

<li><a href="index.php">Home</a></li>

After:(Example: Desktop is whatever folder you may have index.php in. Im just assuming.)

<li><a href="Desktop/index.php">Home</a></li>
1
On

If your file is in a folder named test within your includes folder then you have to first resolve the path to your includes by using the following function

get_include_path();

So now you can use this function along with your previous code. below is an example:

    <?php

      //get the include path
      $pathToIncludes = get_include_path();

     //include the file
     include "$pathToIncludes/navbar.php";

?>

Here is a link to the PHP API http://php.net/manual/en/function.get-include-path.php I hope this helps