• 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

"There is no active transaction" when refreshing database in Laravel 8.0 test

PHP Imap , php 7.4.3 on mac osx catalina

Connecting an HTML webpage to a SQL Server

str_word_count() function doesn't display Arabic language properly

laravel 5.6 bulk inserting json data

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

PHP - Store information with NO database

Class AppHttpControllersUserController Does Not Exist

PHP and WebView - Cookie doesn't are the same

How do I do HTTP basic authentication using Guzzle?

How to use React Router with Laravel?

How can I get user id from session in javascript?

PHP mail sending empty mails

Laravel SQL query midnight time not showing

Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

About Contact Privacy policy Terms and conditions