• 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

Mobile browsers are adding .html to filename on download

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

php 7 php.ini upload_max_filesize not working

Laravel UUID generation

add uri parameter to Route name in laravel

Respond with status code 401 on authentication failure using Laravel and Passport?

Laravel no logout option from menu after successfull login

Add restriction to WooCommerce coupons by allowed user ID

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

JQuery content editable div and text box on submit not sending POST

Why the name of trucks are same in 2nd and 3rd record of company data retrieval?

Object of class stdClass could not be converted to string error

Maatwebsite Excel 3.1 : how do I skip duplicate data when imported?

Cannot connect to own websocket server when on secured domain

How can I get a div content in php

About Contact Privacy policy Terms and conditions