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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:43:43+00:00 2026-06-17T14:43:43+00:00

When I include a file like this: include(/testsitedir/include/subdir/inc.php); on a file named this.php within

  • 0

When I include a file like this: include("/testsitedir/include/subdir/inc.php");
on a file named this.php within the testsitedir folder, I get the typical failed to open stream: No such file or directory in ...\testsitedir\this.php error.

However, when I write a simple HTML anchor tag: <a href="/testsitedir/include/subdir/inc.php">Test Link</a> (URL is identical to the include’s) The browser automatically resolves the URL for me and knows that the / indicates my site root.

How, then, can I make my includes resolve the URL in the same fashion that the HTML anchor tag does?

To get a better understanding, here is what I am trying to do. I have a header file located in a sub directory named content which is within the site’s root directory. I am trying to figure out how to include the header on every file using the same URL. My approach is to just use an absolute URL to the header file. The reason this has become an issue is because I want to be able to readily change the site’s root using a single CONSTANT. Also, the site’s root directory will not always be the server’s root directory. So when I want to put the site on a server in a sub directory www.example.com/view/site/siteroot/ I would define a constant SITE_ROOT to be /view/site/siteroot and include any files using include(SITE_ROOT."/includes/file.php); But the include doesn’t recognize the / forwardslash as a site root delimiter. I was going to use the actual site name but I don’t want to enable url_include for security reasons.

  • 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-06-17T14:43:44+00:00Added an answer on June 17, 2026 at 2:43 pm

    Use the DOCUMENT_ROOT variable defined in PHP:

    include($_SERVER['DOCUMENT_ROOT'] . "/testsitedir/include/subdir/inc.php");
    

    From the docs the variable contains:

    The document root directory under which the current script is
    executing, as defined in the server’s configuration file.

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

Sidebar

Related Questions

I have a php file that looks like this: <?php include(config.php); // put the
i want to include a php file .module file like this using hook_init function
I have the Index file like this <?php include('file1.php'); include('file2.php'); ?> in file1.php I
When I have a header file like this: #ifndef GAMEVIEW_H_ #define GAMEVIEW_H_ #include <SDL/SDL.h>
I have a cpp file like this: #include Foo.h; Foo::Foo(int a, int b=0) {
I'm trying to include a .js file like this: <script src=javascriptfile.js></script> But, what I
I have a php file like this class Config { public static $__routes =
I am read from a file like this: #include <stdio.h> int main() { FILE
My form action is set to a php file like this: <form name=addstudent action=includes/data.php?act=enquiry
My code looks somehow like this: //INCLUDES FILE *file; void handlesocket(int socket); int main(int

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.