answersLogoWhite

0


Best Answer

If you want to save a variable to be used in the same script at different executions by the same user, you should try using sessions. Start a session (session_start()) and retrieve the variable in question (for example, $_SESSION['var']). Throughout the script, edit the variable ($_SESSION['var']) and it will automatically be saved for the next execution by the same user.

Alternatively, if you want the value of the variable to be accessed by all users (and allow all users to edit the variable), do as stated above, but before starting the session, define a session name with the session_name() function. All users will refer to the session defined in the session name, thus using the same variable despite the user.

See the related links for further help using sessions.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you keep the value of a variable between different executions of the same PHP file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why use awk -v command?

This is used when you want to give a variable in an awk script a value before the script starts executing, even before the BEGIN block. You would do this on the command line if the variable needs different values for different executions rather than hardcoding it in the awk script itself.


What is a continous variable?

a variable that can take on many different values, in theory, any value between the lowest and highest points on the measurement scale.


What is the difference between an array shift and unsetting a variable in PHP?

By shifting the values in an array, you are moving a key's value to the previous key. The very first key's value is obliterated. By shifting all values in the array, all keys will have a value of NULL. Unsetting a variable is entirely different -- performing a variable unsetting causes the variable to have a value of NULL, as if it was never set.


What is the value of a variable?

A variable can have lots of different values - as opposed to a constant which has only one. That is why it is called a variable!


What is the difference between a variable and a literal in prgramming?

a literal is a constant value, the difference is a variable can change it's value.


How is solving for a specified variable in a formula different to finding a solution for an equation or inequality?

With a formula, you know the variable's value, and you have to calculate the value of the function of it. With an equation, you know the function's value, and you have to calculate the value of the variable.


What happens to the value of a local variable when the module in which the variable is declared completes execution and control is passed to a different module?

The local variable goes away and the value is lost.


What is a continuous independent variable?

A variable is something that can take different values. These values may be qualitative (colour, gender, favourite singer etc) or quantitative. A continuous variable must be quantitative such that it can take all values between its lowest (minimum) and highest (maximum). The variable is independentif its value is not affected by the value of any other variable under consideration.


What is difference between variable and constant?

Whether or not you can change its value.


What is a variation of a case structure?

A case structure is a control mechanism that allows different executions depending on value of a label. A variation of a case structure is when the execution is presented different and may not represent the value of the label.


How you can modify an integer variable value in a function?

with an assignment: variable = value variable += value variable /= -3; ...


Variable is the value whose value depends upon the value of the independent variable?

The dependent variable is the variable that depends on the independent variable.