• 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

Converting array to string and then back in PHP

Fetch files from next cloud storage and display in Laravel website

How update php.ini on a Mac OS X Mojave?

Remove country code from phone number?

What is PHP's equivalent of JavaScript's "array.every()"?

php - add comma thousands separator but remove trailing zeros

PHP Discord OAUTH2 code sample not working

Unable to create lockable file - Laravel 8 & PHP 8

How to make a foreign key not using primary key

Lumen - Postgresql setup - Composer

Symfony run hint kernel.secret parameter not found

Custom add to cart button URL for specific product in WooCommerce?

How to fix Call to undefined method AppModelsTableName::factory?

Transpose and flatten multiple rows of array data [duplicate]

Having trouble with PDO queries (Notice: Undefined index)

About Contact Privacy policy Terms and conditions