• 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 to break out of a foreach once a condition is met?

How to Create WooCommerce Subscription Product via. REST API?

Wordpress add responsive srcset header image to theme

How to implement placeholder in a php file for moodle plugin?

carbon generated datetime not stored correctly into the database

Yii2 select2 database exception number of bound variables does not match number of tokens

Split comma separated value from table column into rows using mysql?

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

Vimeo API: how to save a vimeo into a subfolder?

What is the difference between client-side and server-side programming?

How do I pass the dynamic output of a php variable or php function to a CSS variable?

Passing a boolean value from checkbox in Laravel form

Laravel You requested 1 items, but there are only 0 items available

Unable to Edit config.inc.php

Transpose csv file data [duplicate]

About Contact Privacy policy Terms and conditions