The internet is a more complex than it was before. It is always good to safe the web sites and web applications from hackers. The .env file plays a remarkable role in this situation.
A web application file that starts with a dot like .env is not accessible by users. This file is used to secure sensitive data of web applications from outside world.
The .env file is created in the root folder of the project. This is a plain text file. This file defines the environment variables required for an application in key and value pairs.
Suppose we are storing the application name in the .env file.
APP_NAME = Project1
Now, we are retrieving this application name and show in our index.php file.
require_once realpath(__DIR__ . "/vendor/autoload.php");
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv-gt;load();
$app_name = $_ENV['APP_NAME'];
echo $app_name;
In this way we can create all the variables which are required in our project environment and access in our project files.
На этой странице сайта вы можете посмотреть видео онлайн Using environment variables in PHP with .env длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь PHP Explained 21 Май 2025, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 187 раз и оно понравилось 0 зрителям. Приятного просмотра!