• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Load a .env file with PHP

phpenvironment-variables


PHP Snippet 1:

USER_NAME='jfBiswajit'

PHP Snippet 2:

<?php

require_once realpath(__DIR__ . '/vendor/autoload.php');

// Looing for .env at the root directory
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

// Retrive env variable
$userName = $_ENV['USER_NAME'];

echo $userName; //jfBiswajit

Related Snippets

disable two buttons after clicking another button

How to fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

Trying to iterate over a mongodb cursor twice - failing

Issue saving card for customer

Confirm Leave on External Links in Wordpress

Creating a config file in PHP

Laravel phpunit test failing authorization

Check if string contains a value in array [duplicate]

add uri parameter to Route name in laravel

Add and update products to session cart in Laravel

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Undefined Array Key error when uploading image on php

Any AWS EB Laravel route getting 404 Not Found nginx/1.16.1

PHP to search within txt file and echo the whole line

Spam Filter in Contact Form

About Contact Privacy policy Terms and conditions