phpSet-up include path for menu navigation so page links know where the site root is located in order to not break links

Be gentle for I am a dummy and may have now gotten myself a bit confused, so bare with me...

I have not been successful getting my remote server environment to behave like my testing server environment -nor visa versa- in regard to my navigations "include code" that I've included on my various pages (these pages reside inside other folders in the site).

My Menu shows up fine in the pages calling the include to this page this way...

<?php include("../includes/navigation.php"); ?>

But my MAMP testing server seems to want me to also add the root folder in addition to my provided link in each of the menu items, so I altered the link by adding my site root folder, like this...

<a href="/mysite/courses/list.php"

and navigation menu seemed to work, going inside one folder and back out into another (then I realized it was no good when I tested it on my remote server).

I got bad/broken links.

So I changed to something like this for the remote server...

 <a href="/courses/list.php"

Links seem to work on the remote, but I needed to fix it so that the code I go with works on both the testing and remote servers...

So, I'm trying to ~~understand/control/and fix~~ my include_once code to provide proper menu navigation for all my various pages whether I am on my testing server or on my remote server and wether I am in one folder or another. Is this possible? And am I approaching this the right way?

(Currently, I have my root folder with an index page, then inside that, I have 3 folders with misc pages inside them, one of these folders (includes) holds my navigation.php page)

I have been searching for how to get my pages (located in various folders) to recognize where they were, in relation to the sites root folder. As a result of searching I concluded to insert this code into the list.php page in my "courses folder"...

   <?php
   $path = $_SERVER['DOCUMENT_ROOT'];
   $path .= "/includes/navigation.php";
   include_once($path);
   ?>

on one of my pages and then tested it in my testing server (MAMP) - but now the menu does not even show up...I also tried...

       <?php
   $path = $_SERVER['DOCUMENT_ROOT'];
   $path .= "../includes/navigation.php";
   include_once($path);
   ?>

So I am seeking help in understanding - what am I missing in my understanding/execution to get the pages now to show the navigation menu as well as know where it is in relation to the root.

I would welcome any comments to help me understand how to connect the dots to solve this problem...As I read in another post saying to someone else there was a problem with where their site root folder was pointing (that it was pointing to the server root folder, not the site root folder)-

How would I know if this is what my problem is? How do you check this?

I had this same exact problem going on. What I did to solve it was instead of simply using "..includes/nav.php" I used an absolute path to the file. It should look something like this:

"var/www/html/includes/nav.php"

This specifies the exact route to the file. You can find this through your hosting file management page. Log into the file management, find the nav file within the folders, and use the exact url of the file.

Related Articles
  • How to add a library include path for NetBeans and gcc on Windows? Using: NetBeans 7.1.2 MinGW (mingw-get-inst-20120426.exe) gcc 4.7.0 For example, you want to add the directories in C:\Program Files (x86)\Example\1.0\include\ as the include paths. F
  • I have RHEL 5.2, with Boost 1.33 installed. I downloaded boost_1_44_0.tar.bz2. and built it. On completion it showed: The Boost C++ Libraries were successfully built! The following directory should be added to compiler include paths: /home/dfe/Archiv
  • I am trying to use a C library in an Objective-C Xcode project. The libraries directory structure is as follows: -- include/ |-- config.h |-- lib/ | |-- file1.h | |-- file2.h | |-- file3.h The library's docs say to include file1.h, and file1.h includ
  • I drew a small (horizontal / in width) svg to be the background of my website's navigation. My website's navigation takes place a 100% of the browser's viewport and I want the svg image to fill that 100% space. So, using css I set the background of t
  • I'm using eclipse Indigo for windows on windows 7 32-bit and a toolchain based on ARM cross compile toolchain which has the version of glibc-2.9 gcc-4.3.4. My project is currently in C but I'm willing to change it to C++ anytime if necessary; its con
  • How do I obtain the system include search paths of the C preprocessor? This is for a script that parses arbitrary source files and needs to know the full pathnames of the headers they #include. Let's ignore for a moment that the user can alter this s
  • I was wondering how should I add my library include paths and linker paths in Visual Studio so that when I add my project to a repository, another developer checking out my project would not need to go through all the include paths and change them fo
  • I have an old version of boost 1.33.1. I want to build it with a custom gcc binary whih is in a path other than default. I could not find the page on the web so I paste the first part of the gcc-tools.jam form tools/build/v1/gcc-tools.jam. Copyright
  • Samsung Galaxy S3 has an extrenal SD card slot, which is mounted to /mnt/extSdCard. My question is: how to get this path by something like Environment.getExternalStorageDirectory()? This will return mnt/sdcard, and I can't find API for external SD ca
You Might Also Like