• 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

Backend cannot be reached after Typo3 login screen

MySQL default time format UTC or GMT?

WordPress Subquery returns more than 1 row on SELECT

how to create html table in php

Appending data to an anchor tag

How to convert binary string to normal string in php

MySQL upgrade causing unexpected results on simple WHERE clauses

Class AppHttpControllersUserController Does Not Exist

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

Dynamic dropdown Ajax PHP request

How to send upload image through email

Laravel 5 controller sending JSON integer as string

PHP Array split string and Integers

How can I make good efficent AJAX live forms with just jQuery and

How to validate tin and cst using PHP?

About Contact Privacy policy Terms and conditions