• 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 extract price from given url using Xpath?

PhP how to calculate moments with variables rows

PHP password_verify

Insert multidimensional array to codeigniter cart

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

Target Laravelista is not instantiable

Yii2: How to download backup files using spanjeta/yii2-backup?

How to validate tin and cst using PHP?

jwt decode throws Invalid argument supplied for foreach() on php-jwt and codeignitor 4

What is my SQL missing?

image source not readable

Get latest Tweets - What API

carbon generated datetime not stored correctly into the database

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

Laravel - How to properly generate unique slugs from article titles?

About Contact Privacy policy Terms and conditions