php - phpdotenv not working with me and showing blank page
Solution:
For anyone who finds this and wonders why theres is not working. getenv
was marked unsafe a while back, you must instantiate dotenv
in your script with Dotenv::createUnsafeImmutable
to be able to use getenv()
rather than $_ENV
, although it is not advised to do so.
Answer
Solution:
I had the same problem as you, but I solved it with the following code.
<?php
require './vendor/autoload.php';
Dotenv\Dotenv::createImmutable(__DIR__)->load();
$stripeSecretKey = $_ENV['STRIPE_SECRET_KEY'];
echo $stripeSecretKey;
.env
file content
STRIPE_SECRET_KEY=sk_test_1234567890123456
Answer
Solution:
I Used an old version From Node.js and an old version from vlucas/phpdotenv and it works!
Source