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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:52:13+00:00 2026-05-25T21:52:13+00:00

Here’s a sample file structure: page.php db.php folder1/subpage.php folder2/fn.php page.php require_once(‘folder2/fn.php’); folder1/subpage.php require_once(‘../folder2/fn.php’); folder2/fn.php

  • 0

Here’s a sample file structure:

page.php
db.php
folder1/subpage.php
folder2/fn.php

page.php

require_once('folder2/fn.php');

folder1/subpage.php

require_once('../folder2/fn.php');

folder2/fn.php – requires database connection

require_once('../db.php');
/* then gets info from database */

Basically, fn.php contains database functions to get/set information. It requires db.php, which is database connection file. This code works in subpage.php, but not in page.php (getting “failed to open stream: No such file or directory in …” error).

Is there a way (using relative referencing), so that it works in all files no matter of directory level?

Thanks for your help!

  • 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-25T21:52:13+00:00Added an answer on May 25, 2026 at 9:52 pm

    I always use the absolute path to the include. There are a couple ways to do this, this command will return the absolute path

    <?php echo getcwd(); ?> 
    
    But this is what I personally use: 
    <? include $_SERVER['DOCUMENT_ROOT'] . "/includes/analytics.php"; ?> 
    

    no matter where the file is php will have the absolute path.

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

Sidebar

Related Questions

Here's a sample database table : | ID | ProductID | DateChanged | Price
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here's my database: id name parent_id 1 Computers NULL 2 Apple 1 3 Books
Here is my text file forms. S1,F2 title including several white spaces (abbr) single,Here<->There,reply
Here is what I am trying to achieve in PHP: I have this string:
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here is an excerpt from Mixed Effects Models in S and S-Plus page 238
Here is how the the database is layout. I can connect to DB fine.
Here is my current problem: I am trying to create a file of x
Here's a basic regex technique that I've never managed to remember. Let's say I'm

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.