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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:03:03+00:00 2026-05-18T21:03:03+00:00

I am working on a new PHP project now, this time I want to

  • 0

I am working on a new PHP project now, this time I want to get the basics right at the beginning. Previously I’ve found requiring/including files in php a bit of pain, please consider the following structure:

/application_root/index.php
                 /js/...
                 /css/...
                 /php/...
                 /conf/...
                 ...

In the index.php I can certainly use something like:

<link rel="stylesheet" href="css/sample.css" ... />
<script type="text/javascript" src="js/sample.js"></script>

To refer to the included css and js, or even php snippets. However, this would only work in the index.php which resides under the root of my application folder. I reckon this is no good.

I came across Java application configuration file “web.xml” where you can define application scope variables that you can simply refer to. .NET with C# has a similar thing. How to achieve this in simple php code so that from any php file in my app, I can type:

<?php echo "<link href='".$application_root_url."/php/sample.css' ..."; ?>

And it will evaluate to the right location?

I am thinking to use:

  • Global variables <== bad practice as violation to OOP? I stop doing this since c programming;
  • set_include_path <== so php will look for it, requires unique name and proper naming convention?
  • load variables from ini files? <== how to make this happen?
  • any new thoughts?
  • 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-18T21:03:04+00:00Added an answer on May 18, 2026 at 9:03 pm

    You don’t want to use global variables because they break encapsulation.

    set_include_path will do no good especially if you are using those variables in HTML, because the include_path is relative to the application’s filesystem path and not to its base url.

    Determining the application base paths is generally not done from a configuration file, as it easy to detect when your application has a gateway script. Since those are constant values, it makes sense to define a constant:

    define('APP_ROOT', dirname(__FILE__));
    define('APP_URL', dirname($_SERVER['PHP_SELF']));
    

    If you want to parse INI files however, you could use parse_ini_file, or parse_ini_string (>=5.3.0):

    $config = parse_ini_file(APP_ROOT.'/'.CONFIG_DIR.'/database.ini');
    echo $config['host'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I am working on a web project in PHP and for the
I am PHP programmer now. And I am writing new project. When I want
I'm not sure why this SQL query is not working. I'm new to SQL/PHP
This is working fine in core php, but not in magento. $party_payment = new
I recently started a little project in PHP, I'm sort of new to this
I am new to Php and I ll be working for a fresh project
Right now I'm working on PHP. I am using the Doctrine ORM and the
I'm working on a new php project with CodeIgniter and I have few questions
Hi I'm really new to php/mysql. I'm working on a php/mysql school project with
Right now I am working with my first Windows Mobile project and I have

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.