• 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

How to add class name to an existing tag in php

jQuery Ajax Post with data

Getting error: CodeIgniterDatabaseBaseResult::getResult in CodeIgniter

Losing session data after POST from third party website

PHPMetrics option --excluded-dirs="myfolder" : myfolder dir is not excluded within docker

PHP password_verify

Message: Set sys_temp_dir in your php.ini after installed composer

PHP rotate matrix counter-clockwise

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

Add bold text and line break into Laravel Notification Email

How to Display Data in Yajra Datatables Laravel 7?

Trying to iterate over a mongodb cursor twice - failing

Artisan, creating tables in database

Destroy session upon refresh

Laravel Model save() & update() Not Saving

About Contact Privacy policy Terms and conditions