• 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

Add 2 Webcam in one page with WebcamJS

Facebook PHP SDK - will not logout properly

Fatal error: Array callback has to contain indices 0 and 1

Smarty if isset

Custom add to cart button URL for specific product in WooCommerce?

Laravel display validation error

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

Execute only one time and then wait set period of time before executing again

How to find the date a user created their Google account

Could not decode a text frame as UTF-8.

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables 11 [closed]

Creating live search with AJAX and CodeIgniter

"cannot list resources" error from WooCommerce REST API

PHP/HTML: Creating A SubMenu

About Contact Privacy policy Terms and conditions