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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:47:35+00:00 2026-05-28T13:47:35+00:00

So I have these files: / | + include/ | | | + database.php

  • 0

So I have these files:

/
|
+ include/
|   |
|   + database.php
|
+ cart/
|   |
|   + table.php
|
+ cart.php

My cart.php displays the page with a table that was generated by table.php (included file). The reason that I have a separated file for the table is because I have to generate the table again after some operations in cart.php — the current table is removed and a new one is loaded with Ajax. However, my table.php file has this line:

require_once("include/database.php");

This is quite problematic, since when the file is included from cart.php, the path makes sense. But when it’s called by itself, the current directory will be cart/ and there is no include directory in cart/.

Is there any way to fix this problem? I’d like to avoid using the big absolute path. Is it possible to tell PHP that include/ should be always searched for files, no matter where it was called? It it is, where should I do that (in which file)?

  • 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-28T13:47:36+00:00Added an answer on May 28, 2026 at 1:47 pm

    If you are using .htaccess, you can set include path :

    .htaccess:

    php_value include_path "/path/to/include/"
    

    php file:

    require_once get_include_path().'file.php';
    

    Another way :

    require_once($_SERVER['DOCUMENT_ROOT']."/include/database.php");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
I have this code which will include template.php file from inside each of these
Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
I have an inc file that contains 4 MySQL database variables - hostname, database,
I have a php page in which I want to include another php page,
I have to include many header files, which are in different sub-directories. Is there
Is there a way to have Expression Language (EL) expressions included JavaScript files be
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
I have a folder with these files: alongfilename1.txt <--- created first alongfilename3.txt <--- created
I have 4 files sorted alphabetically, A, B, C, and D. These files contain

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.