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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:54:17+00:00 2026-05-10T19:54:17+00:00

As many do I have a config.php file in the root of a web

  • 0

As many do I have a config.php file in the root of a web app that I want to include in almost every other php file. So most of them have a line like:

require_once('config.php'); 

or sometimes

require_once('../config.php'); 

or even

require_once('../../config.php'); 

But I never get it right the first time. I can’t figure out what php is going to consider to be the current working directory when reading one of these files. It is apparently not the directory where the file containing the require_once() call is made because I can have two files in the same directory that have different paths for the config.php.

How I have a situation where one path is correct for refreshing the page but an ajax can that updates part of the page requires a different path to the config.php in the require_once() statement;

What’s the secret? From where is that path evaluated?

Shoot, I was afraid this wouldn’t be a common problem – This is occurring under apache 2.2.8 and PHP 5.2.6 running on windows.

  • 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. 2026-05-10T19:54:17+00:00Added an answer on May 10, 2026 at 7:54 pm

    The current working directory for PHP is the directory in which the called script file is located. If your files looked like this:

    /A    foo.php    tar.php    B/        bar.php 

    If you call foo.php (ex: http://example.com/foo.php), the working directory will be /A/. If you call bar.php (ex: http://example.com/B/bar.php), the working directory will be /A/B/.

    This is where it gets tricky. Let us say that foo.php is such:

    <?php require_once 'B/bar.php'; ?> 

    And bar.php is:

    <?php require_once 'tar.php'; ?> 

    If we call foo.php, then bar.php will successfully call tar.php because tar.php and foo.php are in the same directory which happens to be the working directory. If you instead call bar.php, it will fail.

    Generally you will see either in all files:

    require_once realpath( dirname( __FILE__ ) ).'/../../path/to/file.php'; 

    or with the config file:

    // config file define( "APP_ROOT", realpath( dirname( __FILE__ ) ).'/' ); 

    with the rest of the files using:

    require_once APP_ROOT.'../../path/to/file.php'; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many languages have standard repositories where people donate useful libraries that they want others
I have a config file that contains a list of strings. I need to
Many applications have grids that display data from a database table one page at
I have many items inside a list control. I want each item to have
I have many jobs that have a step to send 1 specific email out
Many websites have the concept of sending messages from user to user. When you
Many languages have a facility to check to see if an Object is of
I have many years of experience in Java including Swing, Servlet and JDBC, but
I have many emails coming in from different sources. they all have attachments, many
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,

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.