• 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

PHP Imap , php 7.4.3 on mac osx catalina

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

The difference when using if statement true === something() vs something() === true [duplicate]

JQuery content editable div and text box on submit not sending POST

Open a popup box after receiving result from ajax

Laravel phpunit test failing authorization

Get sum of arrays inside array

Last order would be re-order in wooCommerce. How is it possible?

Boolean assignment operators in PHP

Attempted to call an undefined method named "get" of class "MailController"

SlimExceptionHttpNotFoundException

Reading input in php from terminal

Center point of multiple gps coordinates with php

how to see if database exists with PDO [duplicate]

Woocommerce Checkout - Add conditional field required if one field is filled

About Contact Privacy policy Terms and conditions