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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:07:49+00:00 2026-05-27T03:07:49+00:00

My file structure: /holiday/admin/list.php /holiday/includes/functions.php # common functions /holiday/index.php # / is the document

  • 0

My file structure:

/holiday/admin/list.php
/holiday/includes/functions.php   # common functions
/holiday/index.php

# / is the document root
# /holiday/ is a "self-contained" sub-directory
# There are other "self-contained" sub-directories e.g. /promotion/, /international/

In functions.php I have a common function to generate the <head> part of an HTML; also, a function to return an absolute path from the document root. Note my attempt to calculate /holiday/includes/.

<? function get_path() {
  // Technically, this returns dirname(__FILE__) - $_SERVER['DOCUMENT_ROOT']
  return str_replace($_SERVER['DOCUMENT_ROOT'], "", dirname(__FILE__)); 
} ?>

<? function open_page($head = "", $body_id = "") { ?>
<!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="<? echo get_path() . "/../css/savvyextras.css"; ?>" />
<script type="text/javascript" src="<? echo get_path() . "/../scripts/modernizr.js"; ?>"></script>
...
<? } ?>

functions.php is included this way:

// From list.php
require_once('../includes/functions.php');
open_page(...);

// From index.php
require_once('./includes/functions.php');
open_page(...);

I feel like there must be a more straightforward approach to accomplish the same thing here. Any built-in PHP function for my get_path()? Maybe I should approach my problem differently?

Note:
Some folks suggested using a framework (which is a good thing). But, to help me (and others) understand this whole include-file thing, other non-framework explanations?

Related Discussions:

  • Absolute Path for Deployment in a Non-Root Location
  • Including files by relative path
  • 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-27T03:07:49+00:00Added an answer on May 27, 2026 at 3:07 am

    After experimenting more with this and gathering other inputs, I find using constant will do the trick:

    # functions.php
    
    define('PREFIX', '/holiday');
    
    <? function open_page($head = "", $body_id = "") { ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <link type="text/css" rel="stylesheet" href="<?php echo PREFIX; ?>/css/savvyextras.css"; ?>" />
    <script type="text/javascript" src="<?php echo PREFIX; ?>/scripts/modernizr.js"; ?>"></script>
    ...
    <? } ?>
    

    So, if you need to move /holiday/ to a different sub-directory e.g. /vacation/, you’d simply need to change one constant i.e. PREFIX.

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

Sidebar

Related Questions

I have the following file structure: cron.php /includes/functions.php /classes/ClassName.php corn.php includes functions.php calls new
The file structure looks like this root root/x root/x/y.php root/index.php .htaccess code RewriteRule (.*)
I have the following file structure: /framework /.htaccess /index.php and the following rules in
My file structure looks something like this: ROOT ├── Admin │ └── python_script.py └──
File structure is as follows: index.php settings/ |-manage_account.php templates/viriditio-v2/ |-index.tpl templates/virditio-v2/css |-style.css localhost/~braden/virditio/index.php shows
This is the file structure of my website app/view/home.php .index.php .htaccess Now, I want
I have the following file structure (XML files 'index.xml' in nested folders): index.xml foo/index.xml
My python project has the following file structure: /main.py /functions /functions/func1.py /functions/func2.py /functions/func3.py /funcitons/__init__.py
My website file structure currently looks like this: marketplace.php cats.php On marketplace.php I have
I've got the following file structure: / +--- inc/ | +--- lib1.php +--- inc2/

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.