• 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

Creating Combinations of Elements

how to prevent float variables displaying as scientific notation when printing [duplicate]

"There is no active transaction" when refreshing database in Laravel 8.0 test

Laravel Carbon throws error The format separator does not match

PHPExcel file download using AJAX call

Symfony run hint kernel.secret parameter not found

How to write PHP in XSLT

Call to a member function givePermissionTo() on null

Facebook PHP SDK - will not logout properly

How to create custom authentication in laravel 8?

Laravel Livewire: jQuery not working in child component loaded via @if statement

Return multiple values from a function using mysqli_fetch_assoc [closed]

Why does codeigniter & Linux server throws unserialize() session data error when user tries to login

How to loop a tree array with unknown depth and get array blocks?

About Contact Privacy policy Terms and conditions