• 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

Pagekite error: FAIL: localhost:8080 is down

Destroy session upon refresh

PHP function Not Working As Expected From functions.php Include File

PHP 8.1: strftime() is deprecated

How to test a php login connected to a mysql db through xampp?

How to Install Composer Require doctrine/dbal

How to fix 'Data has already been sent to output, unable to output PDF file' in MPDF

Laravel get user data with profile

Explain how this array transposing and flattening function works

Add and update products to session cart in Laravel

PHP - CURL using HTTPS [closed]

Star rating with half star support

CSS file not imported in laravel blade view

How can I create a Download Page with post php method?

Filter WooCommerce related products by Polylang language

About Contact Privacy policy Terms and conditions