• 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

Add Metadata, headers (Expires, CacheControl) to a file uploaded to Amazon S3 using the Laravel 5.0 Storage facade

Mysqli multi query error

php retrieve specific data onclick from database in a list format

Changing font color in javascript

500 Internal Server Error on Ajax request. Not sure the origin of the problem

How can I get user id from session in javascript?

Extract house numbers from address string

How to redirect to another page after n seconds in wordpress without using javascript?

Respond with status code 401 on authentication failure using Laravel and Passport?

Laravel relationship belongsToMany with composite primary keys

browsersync doesn't work with XAMPP

PHP Get value from JSON [duplicate]

PHP array sort and remove duplicates by two field values

Sentry on Symfony: how to exclude `NotFoundHttpException`

send email using gmail-api and google-api-php-client

About Contact Privacy policy Terms and conditions