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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:39:21+00:00 2026-06-04T20:39:21+00:00

I want to have a constant (a string) that is available to all PHP-scripts

  • 0

I want to have a constant (a string) that is available to all PHP-scripts on the server.

According to http://php.net/manual/en/function.parse-ini-file.php this is quite easy if you parse an extra .ini file, however I don’t want to parse an extra file, I want to set my constant in the global php.ini without having to parse anything in the scripts. (In fact that’s the whole point because I need the constant to find the stuff to include/parse/etc: When I know where this extra .ini file would be, I don’t need it anymore!)

Just inventing a new constant in php.ini and then trying to access it with ini_get() does not work, is there any other way?

I compile Apache and PHP myself, so I could also set the constant at compile-time and/or use Apache-constants if that is neccessary.

  • 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-04T20:39:22+00:00Added an answer on June 4, 2026 at 8:39 pm

    You can use a PHP auto_prepend_file script in your PHP ini to do this as it will be run before any of your user-land scripts:

    Specifies the name of a file that is automatically parsed before the
    main file. The file is included as if it was called with the require
    function, so include_path is used.

    So you can add an ini line like:

    auto_prepend_file="/home/user/script.php"
    

    The in /home/user/script.php:

    define('CONSTANT_NAME', 'your nice value here');
    

    Now in your PHP scripts you can access CONSTANT_NAME from wherever you like as it is available in all PHP scripts.

    I use this technique on my staging server that uses mod_rewrite based mass virtual hosting so I can give my PHP scripts an accurate document root. I have discussed this in a blog post before.

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

Sidebar

Related Questions

I'm using python, and I want a function that takes a string containing a
I want to implement a String comparison function that doesn't take a different amount
I have a description´s textbox that I want to add to some constant text
If I have a collection of static constants that I want to declare centrally
I want to have a java app running, using a function/method (with as little
I want to have my site urls look like http://example.com/place/info?var=info&morevars=ifneeded Place and info are
I have a class called 'Constants' that I am storing a String variable in.
I want to force subclasses to define a constant value. Like const string SomeConstantEverySubclassMustDefine
I have a string containing words that i need to match like the one
I have a class in VB with some constants that represent the string name

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.