• 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

XML to CSV with PHP converter [problem with images grabing]

SQLSTATE[HY000]: General error: 1 table posts has no column named *

Execute only one time and then wait set period of time before executing again

How to add a sidebar to Woocommerce Shop Page?

display WooCommerce “Add to cart” button with short-code [add_to_cart ] dynamically

How to send upload image through email

ldap is missing from system when installing adldap2 in laravel

add_action() function in wordpress not working [duplicate]

PHP Startup: Unable to load dynamic library 'openssl' in Ubuntu

No result using makeStyles Material UI in react 18

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

Normalize DateInterval in PHP

Get WooCommerce product variation attribute terms in admin products general box

CONCAT columns with Laravel 5 eloquent

MongoDB Duplicate Documents even after adding unique key

About Contact Privacy policy Terms and conditions