• 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

The difference when using if statement true === something() vs something() === true [duplicate]

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

best way to store error messages in Laravel (session or variable)

jwt decode throws Invalid argument supplied for foreach() on php-jwt and codeignitor 4

Laravel update hasMany relationship using saveMany

How do I pass the dynamic output of a php variable or php function to a CSS variable?

How to convert binary string to normal string in php

PHP usort() order in case of equality

Laravel 5 session not persisting after user is logged in

Display the WooCommerce product price inside a custom function

PHP how to detect if running on arm64 cpu?

How to keep value of selected value after form submission?

Laravel Delete and Update

How can I get user id from session in javascript?

Can't call javascript alert alertify library from PHP

About Contact Privacy policy Terms and conditions