PHP navigation links work on localhost, but not on the live's server public_html

StackOverflow https://stackoverflow.com/questions/22160263

  •  19-10-2022
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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>
";

نصائح أخرى

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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top