Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to load data from .env file in php

// You can use symfony/dotenv. First install it with composer
// with this command: composer require phpmailer/phpmailer

// Then add this in your code:
use SymfonyComponentDotenvDotenv;
require './vendor/autoload.php';

$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/../.env'); // please update this path for your case

// You will get the variable both in
// $_ENV['ENVIRONMENT_VAR'] and $_SERVER['ENVIRONMENT_VAR'].
$password = $_SERVER['ENVIRONMENT_VAR'] ?? '';
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #load #data #file #php
ADD COMMENT
Topic
Name
2+2 =