Create a superglobal php variable

Asked

Viewed 88 times

-1

I’m creating a website, and all my functions that I use on it are in a file called Funct.php.

So when I have to use some function, I have to call these files using the request Funct.php and, depending on the folder I’m in, I have to add "../".

I observed the laravel framework and he has a file .ENV where have the variables of connection with the database, so these variables are considered "superglobal" such as the post or get.

For this reason I wanted to know how to create a variable superglobal so that I can call anywhere without the need to use the Request

  • You mean require? Laravel uses this: https://github.com/vlucas/phpdotenv

1 answer

0


For this you have to have a file that will be called on all pages, or with require or with include, Example I work a lot with global variables, in my case I use constant, and use as follows

  1. I have a file called config.inc.php
  2. This file is present on all pages of my website

the code goes something like this:

// Definição de Dados do Site
define('NOMESITE', 'PortalCod');
define('RAIZ'    , 'http://localhost');
define('LOGO'    , '<h1><font style="color: #0099cc " >Por</font>tal<font style="color: #0099cc " >Cod</font></h1>');

So I have a basic rule at the time of developing the site which is the following, the configuration file has q be present on all pages

include './inc/config.inc.php';

Usually this is the first line of all my files.

  1. Create a global file (common file with the data you want to use on the entire site)
  2. Use include to include this file in all pages
  3. Create the constant define('NOMESITE', 'PortalCod');

And when you want to use you will call them so: <?php echo RAIZ; ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.