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

  • Home
  • SEARCH
  • 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 6601169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:43:06+00:00 2026-05-25T18:43:06+00:00

I have a single PHP file that i require in many different php files.

  • 0

I have a single PHP file that i require in many different php files.

The PHP file stores DB info and also requires another file called something.php….

Now, say I stored the PHP file (with db info) called my_db_info.php in a folder called config.

I then have another PHP file that was stored in two folders above the config folder, called all_functions. Now to require the file with db info I’d write require('folder1/config/my_db_info.php'); Now this would require my_db_info.php fine but the file required in my_db_info.php (something.php) will not be included which will cause a fatal error.

so when I test the php in the all_functions folder, i get a fatal error telling me that the file (something.php) required in the actual db file (my_db_info.php) could not be found.

then, when I alter the my_db_info.php file and change the require line to decrease how many folders it goes up or down, example:

require('../something.php');

To

require('../../something.php');

It seems to work. But i have to change the folder up/down count to what the main file (in the all_functions folder) is. so as if i was requiring something.php in that file…

Which means, when i want to require my_db_info.php into another file, which is in a completely different location to the file in the all_functions folder (5 folders up for example), I will have to make another my_db_info.php for it to all work properly….

Why does this happen, and is there any way I can fix this?

Thanks

  • 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-25T18:43:07+00:00Added an answer on May 25, 2026 at 6:43 pm

    To me, it seems the easiest thing for you to do, is the directly include the PHP files rather than giving the relative path (which is how you’re including them).

    Try using $_SERVER[‘DOCUMENT_ROOT’] (which will give you something like /home/username/htdocs)

    If I understand your setup correctly, you have the following 2 directories in a directory (possibly in the root):

    /
    /all_functions
    /config
    

    The instead of including with multiple include("../my_db_info.php"); change to include($_SERVER['DOCUMENT_ROOT']."/config/my_db_info.php"); and repeat as needed be for other directories.

    If you do it this way, it will work for multiple directories away from where the config+all_functions directories are located.

    Edit (in response to comment)

    If $_SERVER['DOCUMENT_ROOT'] is unavailable, then you could always manually write the document root, then define it as a constant, then call it in each script.

    Eg.

    define(rootpath, "/home/username/htdocs");
    include(rootpath."/config/my_db_info.php");
    

    Then you can use rootpath as your defined constant in my_db_info.php (etc) if needed be, the downside is that you’d have to write this in every script – though fingers crossed that $_SERVER['DOCUMENT_ROOT'] is available for you.

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

Sidebar

Related Questions

Is that possible to have a single PHP SOAP server which will handle requests
I have a single spool mbox file that was created with evolution, containing a
I have a function in a functions.php file that defines certain variables: add_action( 'the_post',
I load a single instance of a window on php-gtk, I have a button
I have an single threaded, embedded application that allocates and deallocates lots and lots
I have a single user java program that I would like to have store
I have a single line CEikLabel in my application that needs to scroll text.
I have a single Rails 2.2.2 app that I want to 'share' with multiple
I have a log file that looks like the following: 2010-05-12 12:23:45 Some sort
I have a single windows shell command I'd like to run (via EXEC master..xp_cmdshell)

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.