• 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

Hide specific products from unlogged users based in product category in WooCommerce

(Cache::lock()) -> get() -- Under what conditions does it return false?

add_action() function in wordpress not working [duplicate]

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

How to get median and quartiles/percentiles of an array in JavaScript (or PHP)?

shell errors running php exec

Implode columnar values between two arrays into a flat array of concatenated strings

PHP Startup: Unable to load dynamic library 'openssl' in Ubuntu

phpunit - mockbuilder - set mock object internal property

How can I get new CSRF token in LARAVEL by using ajax

PHP password_verify

Send same name multiple checkbox values via ajax

Get sum of arrays inside array

How to validate tin and cst using PHP?

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

About Contact Privacy policy Terms and conditions