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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:58:21+00:00 2026-06-02T00:58:21+00:00

I have a config file with the general configuration (in a git repo), and

  • 0

I have a config file with the general configuration (in a git repo), and a local config file that overwrites configuration properties (ignored in the repo). Right now the local config file is included at the beginning of the config file:

include_once 'local_config.php';

But I would like the include to be conditional: only do it if the file local_config.php actually exists. I can do a enter link description here without problems, but first I would need to check if the file exists. So I tried get_include_path() but it returns a list of paths, and I would have to parse this list and check for every one.

Another option would be to just call include_once() and suppress the warnings, but it is even messier. Is there a simpler way to do a real optional include in 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-06-02T00:58:22+00:00Added an answer on June 2, 2026 at 12:58 am

    Use the file_exists() predefined PHP function like so:

    // Test if the file exists
    if(file_exists('local_config.php')){
        // Include the file
        include('local_config.php');
    }else{
        // Otherwise include the global config
        include('global_config.php');
    }
    

    Documentation here: http://php.net/manual/en/function.file-exists.php

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

Sidebar

Related Questions

I have a config file that I read using the RawConfigParser in the standard
I have a large config file (user) that i needed to go to the
I have set an array in my config file that I use global in
Hi so I have a file called config.m that contains a list of variables
I have an App.config file in my project that gets copied to NameOfExe.exe.config at
I have an application that uses xml config file, where I'm describing layouts for
In a servlet I have a config text file. How to prevent web access
I am using php and mysql. I have a Database config file (db-config.php) which
I have configured my Web.Config file as follow in a ASP.NET MVC 2 project:
i have an edited version of a config file specific for my machine. i

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.