Giter Club home page Giter Club logo

appsalon's Introduction

Variables de entorno

En la terminal, instalen el siguiente paquete:

composer require vlucas/phpdotenv

Crean un archivo ".env" en la raíz del proyecto junto a otro ".env.example" (el ".env.example" se sube al repositorio, pero sin datos). Luego, colocan las siguientes variables (pueden incluir las del MAILTRAP o no, es opcional pero recomendable):

#CONNECTION DB_HOST = "" DB_USER = "" DB_PASSWORD = "" DB_DATABASE = ""

#CONFIG MAILTRAP MAIL_MAILER = "" MAIL_HOST = "" MAIL_PORT = MAIL_USERNAME = "" MAIL_PASSWORD = "" MAIL_ENCRYPTION = ""

Lo importan de la siguiente manera en la función de la conexión en la base de datos:

use Dotenv\Dotenv;

Ya por último, colocan el siguiente código para usarlo:

$dotenv = Dotenv::createImmutable('DIRIGIR A RAIZ DEL PROYECTO'); $dotenv->load();

//Aqui salen errores: $db = new mysqli($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_DATABASE']);

Para que no se suba al repositorio, en la raíz del proyecto crean el archivo ".gitignore", colocando el siguiente código (Incluso, ni se suben las carpetas del node_modules ni el vendor):

/node_modules /vendor .env

Ya quedaría listo, incluso para el PHPMailer no se tiene que volver a importar el uso del DOTENV, sólo úsenlo con esta variable: $_ENV['NOMBRE_VARIABLE'];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.