Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 471829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:01:31+00:00 2026-05-13T00:01:31+00:00

I recently decided to incorporate PHP into my website, but I’ve never worked with

  • 0

I recently decided to incorporate PHP into my website, but I’ve never worked with it before so I’m not familiar with the functions…

My problem is that I am using the include() method for my header and footer on each PHP page like this:

<?php include('../php/header.php'); ?>

This navigates from /public_html directory to the /php directory in the root of my website. To account for the different sub-directory levels that files may be located, at the top of each PHP page I add:

<?php
/* Path prefix so relative links work correctly */ 
$path = "../";
?>

and ../ could be replaced with ../../ for a file another sub-directory down and so on, and in the header and footer files, links are preceded like this:

<a href="<?php echo($path); ?>index.php" title="Home">Home</a>

and everything works fine like this…until I try to use it with wordpress which is located in a sub-directory on my website. WordPress uses dynamic pages and so sometimes pages are located in a sub-directory lower than other pages and the links will fail to work with this method. In my old site design, I used the tag to set all link references to the root/public_html directory of my site. However, PHP is not affected by this tag. What I need is a method to set the the link references from the /public_html directory for my include() methods on the blog.

Is there such a method or is there a better way to do what I am doing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:01:31+00:00Added an answer on May 13, 2026 at 12:01 am

    Say your config file is in /system/config.php. in config.php add…

    define( 'DIR_BASE', dirname( dirname( __FILE__ ) ) );
    define( 'DIR_INCLUDES', DIR_BASE . 'includes/' );
    

    Now as long as your config.php file doesn’t move, your base directory will always be 2 directories below it. You can use these in all of your files that include config.php.

    require DIR_INCLUDES . 'header.php';
    

    Now you don’t have to worry about where you are in your site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been diving into Erlang recently, and I decided to use Mnesia to do
I've recently decided that I just have to finally learn C/C++, and there is
This is starting to vex me. I recently decided to clear out my FTP,
I started a Rails project recently and decided to use RESTful controllers. I created
I'm a beginner (self-learning) programmer learning C++, and recently I decided to implement a
I recently started a new webforms project and decided to separate the business classes
I've recently seen the light of EventWaitHandle's powerful behavior in C# and decided to
I recently decided to try some java web development, so I installed xampp, the
I recently decided that I needed to change from using milliseconds to microseconds for
I recently decided to try emacs for java development, so this is the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.