Question

I am working on a website shared by two other people. We all need to upload it to our schools live servers.

Now instead of rewritting navigations,and using relative path ../../../ for every single page, we decided to just use php. Here is the include for the html.

php include('../../php/includes/navbar.php')

Here is the php code for the global navbar: navbar.php

$base= 'http://localhost';            
echo "
<ul class=navbar>
 <li <a href='$base/index.php'> Index </a> </li>
 <li><a href='$base/src/devices/devices.php'>Devices</a></li>
 <li><a href='$base/src/howto/howto.php'>How To</a></li>
</ul>
";

Now the links work just fine when I use my home computer, with xampp. But when I upload the site to my school's server, the links are broken.

By the way the website's index.php resides in the

www.cs.uml.edu/~USER_NAME/public_html/gameworld/

Any help will be greatly appreciated, thank you very much.

Was it helpful?

Solution

In local your server base is

   $base= 'http://localhost';            

and in server it should be

$base= 'http://www.cs.uml.edu/~USER_NAME/public_html/gameworld'; 

and final code

$base= 'http://www.cs.uml.edu/~USER_NAME/public_html/gameworld'; 
echo "
<ul class=navbar>
 <li> <a href='$base/index.php'> Index </a> </li>
 <li><a href='$base/src/devices/devices.php'>Devices</a></li>
 <li><a href='$base/src/howto/howto.php'>How To</a></li>
</ul>
";

OTHER TIPS

Notice the $base variable. When you put it on your website make sure it reflects the url of your website and no longer says localhost.

$base should be your website URL

$base = 'http://www.cs.uml.edu/~USER_NAME/public_html/gameworld'

You are missing closing > of the first <li> element too.

<li <a href='$base/index.php'> Index </a> </li>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top