• 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

PHP to search within txt file and echo the whole line

Wordpress add responsive srcset header image to theme

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given [duplicate]

Form repeater send wrong data with last element in Laravel

Display Link Title Instead of URL in XSL

Filter WooCommerce related products by Polylang language

add_action() function in wordpress not working [duplicate]

Laravel Nova, route not found

MySQL order by field in Eloquent

Laravel 5 session not persisting after user is logged in

Fatal error: [] operator not supported for strings

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

Only on Firefox "Loading failed for the <script> with source"

Using array_intersect on a multi-dimensional array

Add custom text under order details on WooCommerce My account view order pages

About Contact Privacy policy Terms and conditions