• 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

Why i get wrong output for html markdown?

Laravel Nova Dependency Container what are the allowed resource properties other than id in dependsOn

PHP: Print caught exception like Xdebug

Issue with laravel eloquent model property

PHP-Sort array based on another array?

Custom post type single page not working

Ajax GET request fails in laravel 8

MySQL default time format UTC or GMT?

Laravel Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttpPsr7Request

Sum array values of a column within each column of an array with 3 levels

Composer fails with kylekatarnls/update-helper on new homestead

Laravel Schedule not sending email

wordpress : How to specify the cause "This site can’t be reached"

Laravel Command Schedule Not Working Properly

Call to undefined function openssl_decrypt

About Contact Privacy policy Terms and conditions