• 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

How do I call a php file with axios?

possible options to create pdf file using html elements to generate invoice in php and codeigniter

Mobile browsers are adding .html to filename on download

Symfony 4: how to allow dynamic values for array nodes in bundle configuration?

WAMP Virtual Host not working

Is it possible to change the table name in the migration file-laravel

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

Call authenticate manually in router middleware

How to convert a carbon into string, to take the date only?

correct PHP headers for pdf file download

How to check user Permissions using Custom Middleware in Laravel

CSV to PHP class properties

Not able to access model in the controller mautic

I want to store data in new index as per my key in php [duplicate]

Warning: A non-numeric value encountered

About Contact Privacy policy Terms and conditions