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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:49:02+00:00 2026-05-22T19:49:02+00:00

I have these three files to work with: document_root/include/config.php document_root/include/database.php document_root/index.php And the relevant

  • 0

I have these three files to work with:

document_root/include/config.php
document_root/include/database.php
document_root/index.php

And the relevant part of the file contents are like below:

config.php

// ...
$MyVar = 100;
// ...

database.php

// ...
require('config.php');
// Aiming to use the definitions in "config.php" here
// ...

index.php

// ...
require('include/database.php');
// Using the code in "database.php" here
// ...

The problem is that, config.php is somehow not included, and yet no error message is given (in E_ALL mode). I can’t access to the definitions in the config.php file from database.php file while running the code in index.php.

In my PHP.ini file include_path is set to C:\...\document_root\include directory.
An PHP version is 5.3.0.

I have observed that, if I change the require() directive in database.php as
require('include/config.php');
the code runs without any failure and everything is just fine. But this solution is not possible in practice, because I’m planing to include the config.php file from multiple locations.

What is the cause of this problem?
How can I fix it?

Any help will be appreciated.

  • 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-22T19:49:03+00:00Added an answer on May 22, 2026 at 7:49 pm

    The cause of this problem is, that include resolves relative filenames based on the working directory, not based on the directory where the file is located that does the include.

    The working directory is the directory of the PHP file that is launched by the webserver (in your case index.php I guess). If that file includes some other file, the working directory is not changed. It can be changed manually using chdir, but you should not do that solely for the sake of an include.

    One possible solution is to use

    include dirname(__FILE__) . DIRECTORY_SEPARATOR . '[RELATIVE_PATH]';
    

    where [RELATIVE_PATH] is the relative path from the file that does the include to the file that is included.

    In PHP 5.3, __DIR__ can be used instead of dirname(__FILE__).

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

Sidebar

Related Questions

There is a data file and some image files that I have to download
I have to include many header files, which are in different sub-directories. Is there
On the SVN server, there is a file called config.conf . I have a
Is there any way to list all the files that have changed between two
Is there a way to unlock Windows files without downloading a utility? I have
I have two XML files. They are similar, but there are two nodes of
Is there a way to have a file that is modified / touched whenever
Is there a way to have an file browser for Flash that allows the
Is there any way to have a Windows batch file directly input SQL statements
Is there any way to have something that looks just like a file on

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.