• 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 to prevent phpmailer sending embedded image as an attachment on Gmail?

Batch request Google Calendar php API

How do I loop through an MS SQL database with VB.NET?

Send same name multiple checkbox values via ajax

Transform array, set each array element with parent key php

How to break out of a foreach once a condition is met?

With doctrine ODM, can I embed many subdocuments in a main document?

Laravel Displaying image from database

Encrypt in php and decrypt in Dart(flutter)

Laravel Pagination links() not working

Can I write PHP code across multiple lines per statement?

How to get monthly wise data in laravel

Using PHP to connect to a remote MSSQL database

How to generate QR CODE for dynamic generating link and logo using Simple QrCode in laravel?

No result using makeStyles Material UI in react 18

About Contact Privacy policy Terms and conditions