php global variables

Asked

Viewed 220 times

0

Hello, I think this is simple, I am working on a project in which I need to start 3 strings on 80% of the system pages, in php, so what would be the best method for the user to just change the text in a document, and I can perform the inclusion on all pages???

explaining better, I will create a configura.php file, where the client will open using a compiler or text editor and set the value of the 3 strings separately.

ps: I’ve been advised to use Session, but my question is how can I load 3 separate strings using Session.

  • You will no longer include the file configura.php in all files? If yes, you don’t have to do anything else. I don’t see why use sessions if the value of these variables is constant.

  • Anderson, I can include the yes file, you could give me an example of the syntax to assign the values coming from configure.php to variables of any page?

  • Sets the variables in configura.php same and in every file you include it they will exist.

  • Andreson, something like that might conflict with variables of the same name, right? But thanks for the tip, I’ll test to see if it works 100% here!

  • puts the comment on Answer the Question so I can give you the reputation points.

  • The reason for the closing vote is that there is no way of saying what is the best way to resolve it. From what you described it seems not necessary to use session variables. The first thing I imagined is constant use, but then you say the user will edit a config.php, and that changes all the logic. What is the format of this config.php and how is it accessed? If you can show what this file looks like, I think you can make the question more objective. Otherwise, you will get answers from others, throbbing what you could do. But using Sesssion, I find it unlikely.

Show 1 more comment

2 answers

4

Create SESSIONS it’s very simple, just do:

session_start(); //Inicia a sessão
//Seta as variáveis
$_SESSION['string1'] = 'Oi';
$_SESSION['string2'] = 'Olá';
$_SESSION['string3'] = 'Eu sou uma string';

0

Daniel if these values are system constants create a file and within it define constants like this:

define(NOME_CONSTANTE1,'value');

define(NOME_CONSTANTE2,'value');

then make a include on the pages you will use.

That’s right in capital letters then use NOME_CONSTANTE1 or NOME_CONSTANTE2 in your script where you want! If the value of these variables is not constant use Session!

Constantes de sistema

  • by the way, how do I show the constants later? obg

  • I did not understand what you meant by show, but if you are referring to printing them use : echo NOME_CONSTANTE1;

  • it was really that. I thought it was necessary something more than that. thank you.

  • Dispose my King!

Browser other questions tagged

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