• 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

Server-sent events in PHP (without echo or print)

Laravel query builder binding parameters more than once

XAMPP/SQLSRV: Unable to find Sqlsrv in PHPINFO(); - errors coming from connection

ConstraintViolationListInterface to Exception in Symfony

Laravel Blade checkbox not checked

zsh: command not found: php

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

how to insert data into select2 search input after scan using qrcode

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

Symfony - EasyAdmin - Add and remove functions are ignored from AssociationField

How to get company posts from LinkedIn via API?

Laravel Multi-language routes without prefix

Redis Command To Sort Keys

In PHP, which is faster: preg_split or explode?

About Contact Privacy policy Terms and conditions