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.
In questa pagina del sito puoi guardare il video online Using environment variables in PHP with .env della durata di ore minuti seconda in buona qualità , che l'utente ha caricato PHP Explained 21 maggio 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 187 volte e gli è piaciuto 0 spettatori. Buona visione!