• 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

javascript html popup window

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

GA4 custom event from server side, can someone tell me how i can do the following code in php?

Unable to run composer install

PHP array, move keys and values to new array, but mix it up

str_replace or preg_replace random number from string

Ajax GET request fails in laravel 8

MySQL - Connection failed: No route to host

Using Associative arrays

json_encode turns array into an object

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

GRPC installed successfully on ubuntu but php is looking for it in another folder

Match csv filenames to table names and import

Composer Warning: openssl extension is missing. How to enable in WAMP

How to keep value of selected value after form submission?

About Contact Privacy policy Terms and conditions