• 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

XSS attack still works despite htmlspecialchars() doing its work

"properties should not be accessed directly" issue during WooCommerce 3.0 checkout

How can I make this nested location configuration use the correct path to call a php program?

Star rating with half star support

google content api for shopping

How to create custom authentication in laravel 8?

Exact alternate to mcrypt_encrypt in PHP 7.2

PHP drop down list using array's and foreach (else and for) code

PHPMetrics option --excluded-dirs="myfolder" : myfolder dir is not excluded within docker

AJAX call fails with SyntaxError: Unexpected end of JSON input

Render the content of default_filter.php in Joomla front-end

Valet, Xdebug after reboot Big Sur not working

Elastic Beanstalk with Laravel Envoy

Converting array to string and then back in PHP

printing all running session variable in laravel 5.1

About Contact Privacy policy Terms and conditions