.htaccess env variables not working

I am using mysqli with environment variables set in .htacess to connect to a external database, which was working fine for months with no changes to that code.

But suddenly, noticed yesterday that, out of nowhere, those environment variables were no longer being recognized, marking them as NULL.
That happened to my 2 websites (since they have the same code for the mysqli connection)

Here’s what’s going on with a test var:

image
Doing just a normal echo (also tested with $_SERVER and getenv

echo ($_ENV[‘Test’]);

And the result:
Warning: Undefined array key “Test” in … /index.php on line 34 (that’s where the echo is)

I have been researching about this problem but in vain.
My assumption is an internal problem or maybe the php upgrades?, might be completely wrong.

But anyways, help is appreciated.

Welcome!

What purpose exactly do you have for environment variables? Generally global and sensitive information is stored within a config.php or .config file.

5 Likes

I use environment variables to store the credentials to connect to the MySQL database with mysqli.

And I set them in the .htaccess file, which is one of the best safe places to store critical information from what I heard.

I don’t see how that would be any safer then just hardcoding them (If you are using them once), or putting them in a config.php file (If you are using them multiple times).

Both cannot be accessed via a browser, and both can be accessed via FTP.

4 Likes

I see,
from my undertanding of what’s going on from the errors I get, the website just no longer reads/accepts environment variables set in .htaccess.

But I have been researching other secure ways to store those credentials and found a way which is currently working.

Thanks for your help anyways.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.