• 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

ORA-12546: TNS:permission denied error connection to remote oracle server

How to set time with DateTime modify?

How to to send mail using gmail in Laravel?

Form repeater send wrong data with last element in Laravel

Hide email address with stars (*)

php script to delete files older than 24 hrs, deletes all files

Show only featured products in Woocommerce shop page

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

Prevent blank space in pdf pages (DomPdf)

Having trouble with PDO queries (Notice: Undefined index)

Laravel no logout option from menu after successfull login

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

PHP: Calling MySQL Stored Procedure with Both INPUT AND OUTPUT Parameters (NOT "INOUT")

api response laravel doesn't show

Make certain characters of a word from string bold

About Contact Privacy policy Terms and conditions