• 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

PHPExcel_IOFactory::createWriter causes wrong behaviour

Laravel Get Days In Month From Month Number?

Stop caching for PHP 5.5.3 in MAMP

shell errors running php exec

How to prevent phpmailer sending embedded image as an attachment on Gmail?

I'm trying to write a clean url for my website using the $_SERVER['REQUEST_URI'] in php

file_get_contents() without "Http" to access external URL [closed]

Popup Window and PHP form

Show date difference as "20" instead of "20 years ago"

Unable to guess the mime type as no guessers are available Laravel 5.2

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

How to create a scheduler application in php

how can I set a session variable in Drupal 8 and get it in a php script?

How to add automatically collapse/expand in content wordpress (single.php)?

PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: no such host known

About Contact Privacy policy Terms and conditions