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 940075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:53:43+00:00 2026-05-15T21:53:43+00:00

So, examining this directory structure /include_one.php /include_two.php /directory/main_file.php Assume that I am in /directory/main_file.php

  • 0

So,
examining this directory structure

  • /include_one.php
  • /include_two.php
  • /directory/main_file.php

Assume that I am in /directory/main_file.php and I call include('../include_one.php'); inside of include_one.php, to include include_two.php. Do I need to call include('include_two.php); or include('../include_two.php');?

So my question is: When including a file, is the ‘relative include path’ shifted to the included file, or does it remain at the main including file?

I am aware that the best alternative would be to have a config.php which contains the root_path, however this is not possible at this stage.


update:
So, im not sure who is right, as here is my test

directory structure

/include.php
/start/start.php
/folder1/includeone.php
/folder1/folder2/includetwo.php

and here is the contents of each file

start.php

<?php 
  echo 'including ../include.php<br />';
  include('../include.php');
?>

include.php

<?php 
  echo 'including folder1/includeone.php<br />';
  include('folder1/includeone.php');
?>

includeone.php

<?php 
  echo 'including folder2/includetwo.php<br />';
  include('folder2/includetwo.php');
?>

includetwo.php

<?php 
  echo 'done<br />';
?>

and the output is

including ../include.php
including folder1/includeone.php
including folder2/includetwo.php
done

  • 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-15T21:53:44+00:00Added an answer on May 15, 2026 at 9:53 pm

    The “relative include path” is not shifted to the included file… Which means that using relative paths generally ends badly.

    A better solution, that I use almost all the time, is to always work with absolute paths — and you can mix relatives and absolute paths using __DIR__, to get the directory that contains the file where this is written.

    For example, in include_one.php, you’d use :

    require_once __DIR__ . '/include_two.php';
    

    To include the include_two.php file that’s in the same directory as include_one.php.

    And, in main_file.php, you’d use :

    require_once __DIR__ . '/../include_one.php';
    

    To include the include_one.php file that’s one directory up.

    With that, your includes will work, no matter from which file they are called.

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

Sidebar

Related Questions

I am examining a core dump, and noticed that in one frame the 'this'
this is not a question about a specific programming problem, it's about examining different
I'm implementing an IHttpModule as described in this question . Since we're examining every
I'm relatively new to WPF. I'm examining some code that looks like this: private
Examining Zend Framework, I found that all setter methods (of those I’ve examined) return
Examining the compiled code of the sinf() on our GCC implementation, I see that
Our environment: Drupal+MySQL Examining the query log indicates that the following query, originating from
in my application I need to dynamically create a type that contains multiple properties.
I've been examining HTTP 1.1 specifications and well I saw something like this: Request-Line
I am examining our legacy system, and there is a method that sends an

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.