Answers for "how to include env.local php"

PHP
2

php set environment variable

putenv('NAME=VALUE');

// NAME may contain whitespaces ->
putenv('NAME=VALUE') 
// is not equivalent to 
putenv('NAME = VALUE')
Posted by: Guest on July-07-2020
0

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 Symfony\Component\Dotenv\Dotenv;
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'] ?? '';
Posted by: Guest on March-08-2022

Browse Popular Code Answers by Language