• 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 can I get a div content in php

Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path: ) in Unknown on line 0

Laravel: Create morphs() relationship nullable

Manage independently the decimal number of the price of each product [duplicate]

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

How can i hide dt if dd got empty value

How do I enable error reporting in Laravel?

str_replace or preg_replace random number from string

Remove country code from phone number?

Laravel Command Schedule Not Working Properly

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

PHP: Print caught exception like Xdebug

PHP: remove filename from path

Symfony Make:Migration : The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue

How to MODIFY a Google Docs document via API using search-and-replace?

About Contact Privacy policy Terms and conditions