• 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

Show Custom Data in Woocommerce Order Details Admin Area

Shortcode or PHP inside a shortcode in Wordpress

Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type

How to override header set in Apache config with more specific header in a virtual host

PHP -> Next nearest date defined by array of days in week

PHP7 CLI attempts to load xdebug twice - "Cannot load Xdebug - it was already loaded"

woocommerce change position of price

Return multiple values from a function using mysqli_fetch_assoc [closed]

How can i hide dt if dd got empty value

Google API Heatmap Layer exception, why?

Facebook SDK error: Cross-site request forgery validation failed. Required param "state" missing from persistent data

XSS attack still works despite htmlspecialchars() doing its work

Prestashop webservice API creating cart rules

Override default Auth routes in Laravel 7

Saving Data from form to database using AngularJS and php

About Contact Privacy policy Terms and conditions