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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:11:06+00:00 2026-06-13T12:11:06+00:00

I’m building a PHP application and I’m not quite sure how to store global

  • 0

I’m building a PHP application and I’m not quite sure how to store global configuration settings that can be truely accessed anywhere – it seems that content that is included cannot access other content included from the main, starting page. For example, if index.php includes foo.php and bar.php, bar.php don’t have foo.php but index.php has both of them – the included files just can’t refer to the other ones. Is this correct?

If yes, how would I set up something like this up?

index.php

<?php
include 'functions/load.php'
echo getHeader();
?>

functions/load.php:

<?php
include_once 'config.php'
include_once 'header.php'
//loads the includes
?>

functions/config.php:

<?php
//I want to store the site URL here.
$siteURL = "http://127.0.0.1";
?>

functions/header.php:

<?php
function getHeader(){
    return "Header for " . $siteURL;
}
?>

How can I set up an config file that can be then accessed anywhere, including inside other included files? Also, is including a file that lists the other includes good practice?

  • 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-06-13T12:11:07+00:00Added an answer on June 13, 2026 at 12:11 pm

    It’s good practice to include a single bootstrap.php file, which will contain all of the necessary requires. The bootstrap should also define an autoloader, which will be able to autoload classes without having to be explicitly required.

    It isn’t possible to autoload functions though, so file(s) containing functions will need to be required in bootstrap.php using require_once(). See this question for other alternatives.

    Ideally you’d only have a single “entry point” to your application, which is referred to as a “Front Controller”. If so, then you’ll only need to require your bootstrap.php once at the top of this file.

    Edit: Note about configuration

    You’d load your configuration within the bootstrap as well. How you do this is up to you…you could just place all your variables directly in bootstrap.php, or else you could require in your configuration from there. Best practice is to store configuration in a separate file.

    Configuration via PHP array:

    # in /path/to/config.php (not in a publically accessible directory!)
    return array(
        'site_url' => '127.0.0.1', 
        'example' => array(
            'animal' => 'cat', 
            'vehicle' => 'car'
        )
    )
    
    
    # in bootstrap.php
    $config = require_once('/path/to/config.php');
    
    # anywhere else
    $siteUrl = $config['site_url'];
    $animal = $config['example']['animal'];
    

    Or you could use an INI file:

    # in /path/to/config.ini (not in a publically accessible directory!)
    [site]
    url = 127.0.0.1
    
    [example]
    animal = cat
    vehicle = car
    
    
    # in bootstrap.php
    $config = parse_ini_file('/path/to/config.ini', true); 
    
    
    # anywhere else
    $siteUrl = $config['site']['url'];
    $animal = $config['example']['animal'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.