• 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

WordPress Security Standards want me to escape my html, but how to do it correctly?

Install mysql client in docker image

500 (Internal Server Error) with Laravel & Docker [duplicate]

How to get values inside <![CDATA[values]] > using php DOM?

Invalid value in field "itemtype" in Google Search Console

How in Laravel run JavaScript code stored in php variable?

PHP Discord OAUTH2 code sample not working

dompdf and img tag, image wont show

Add Class in html Dynamically in PHP

PHP -> Next nearest date defined by array of days in week

Correct way to use LIKE '%{$var}%' with prepared statements?

printing all running session variable in laravel 5.1

Laravel set default language not working

How to set a domain name with php artisan serve

How to submit a form when page loads using JavaScript?

About Contact Privacy policy Terms and conditions