I dislike this approach as it is vulnerable for following situations:
when your application requires CLI commands (such as some CRON-related cleanups) the .htaccess file is unavailable, so the variables will not be correct
when your server hosts more than one application or hosts two instances of the same application (like "test" and "production") setting system-wide environment variables is not accurate
I'd recommend having separate PHP file such as config/environment.php:
<?phpreturn'PRODUCTION';
and exclude it from VCS so it will not be distributed over instances of the application. Instead, in VCS provide an example/dummy of that file, like config/example.environment.php:
<?php// Please copy this file to `environment.php` when you are// setting application up for the first time.// Possible values are: `DEVELOPMENT`, `TESTING`, `STAGING`, `PRODUCTION`return'DEVELOPMENT';
Then include the config/environment.php in application bootstrap, as soon as possible.
Of course the environment.php file can hold more data, like:
When your application requires CLI commands (such as some CRON-related cleanups) the .htaccess file is unavailable, so the variables will not be correct
You can run those cli commands if your are not on a shared hosting environment. In the post i have stated that .htaccess is for those with a shared hosting plan (like the godaddy ones).
You wouldn't use .htaccess if you owned the server where the app is deployed. You would go with the second option i have provided. Set the evironnment variables on the system level. That way if your application requires CLI commands the variables would still be correct.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I dislike this approach as it is vulnerable for following situations:
.htaccess
file is unavailable, so the variables will not be correctI'd recommend having separate PHP file such as
config/environment.php
:and exclude it from VCS so it will not be distributed over instances of the application. Instead, in VCS provide an example/dummy of that file, like
config/example.environment.php
:Then include the
config/environment.php
in application bootstrap, as soon as possible.Of course the
environment.php
file can hold more data, like:You are correct on
You can run those cli commands if your are not on a shared hosting environment. In the post i have stated that
.htaccess
is for those with a shared hosting plan (like the godaddy ones).You wouldn't use
.htaccess
if you owned the server where the app is deployed. You would go with the second option i have provided. Set the evironnment variables on the system level. That way if your application requires CLI commands thevariables
would still be correct.