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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:34:53+00:00 2026-05-24T07:34:53+00:00

I like to refer images, css and php files using their absolute path, that

  • 0

I like to refer images, css and php files using their absolute path, that is starting from root, with an address beginning with “/”.

I need to include php files that are all located at “/bin/res/include”. I figured out I can’t use absolute paths in php as I do in html. After some research I discovered the best method that suits my needs is to

define("PHP_ROOT", "/home/a7503679/public_html/bin/res/include/");

and then to include some file

include_once(PHP_ROOT."filename.php");

I don’t want to paste the first define on every html page. Can I do a global define? Can I define that constant one time at one place and make it known to all html pages? If so, how and where is the global place?


  • I can’t use dirname(__FILE__); because that only gives the full path to the folder where I’m currently in, which may not be the root.
  • I can’t use $_SERVER['DOCUMENT_NAME'] because I’m using a shared hosting service.

[UPDATE:solution] thx everyone, especially RiaD for its idea, this is what I’ve done:

Edited my .htaccess file at the root of my website and added the following line,

#Loads an init php located at <fullpath>/<path-to-folder-with-php-files-to-include>/init.php
php_value auto_prepend_file /home/a7503679/public_html/bin/res/include/init.php

Now all my html files will include that init.php file, so you should (as I did) put there all the common php code you’ll need on every html page, which in my case was:

<?php
define("PHP_ROOT", "/home/a7503679/public_html/bin/res/include/"); #this solves the problem
include 'lang.php'; #translations file
?>

Before I needed to include that lang.php on every page and now it’s automatically done. If I need to include any other php file, using its absolute path, I just type include PHP_ROOT.'filename.php';

  • 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-24T07:34:53+00:00Added an answer on May 24, 2026 at 7:34 am

    You can use auto_prepend_file in your .htaccess

    PS: $_SERVER['DOCUMENT_ROOT'] should work (on shared hostings too)

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

Sidebar

Related Questions

I have a html tag with inline CSS style like: <body><div style="position:absolute;top:100px;"></body> and I
I have a site with index.php in the root folder, images in /img ,
Please refer to the following image: I wanted to group the controls like that.
Using JSF 2.0. Got an app running with CSS and Javascript running from /Servlet/resources/css
I would like to know how I can refer to a list item object
I'm trying to refer to a drive whose letter may change. I'd like to
Like many companies that require all access be through stored procedures, we seem to
How can I resize an image using HTML/CSS only (i.e no server code) while
I would like to refer to a MergedDictionary together with locally declared resources in
I am using Uploadify Plugin to upload images, the parameter response of the uploadify

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.