php - Save user input in a variable and use it on all pages

974

As described above I want the user to enter any value like "minutes" in a form and use it on another page to set a timer.
In order to do that I should use php. I have seen and searched many examples, but I can't find any actual way to use a variable in all of the web pages One example I ran into, was to use:

<?php include"form.php" ?>

but it also prints the content on it by default.

Now what I truly want is:

A variable $minutes = 3; Which will be the default value stored somewhere or maybe even on the form page. I have a form page on which I take the minutes as input from a user and on clicking the submit button the value of $minutes changes into the value provided by the user. Now he can change it again and again and again to 2 minutes, 5 minutes etc etc, but I have no way to send it across multiple pages.

Thank you for your help

485

Answer

Solution:

To have access to your variable on every single of your pages you could store your variable in a session :

<?php 
 session_start();
 $_SESSION['minutes'] = 3;

// rest of your code

and you can access it like that :

 $_SESSION['minutes']

or in a cookie :

 setcookie("minutes", 3);

which you can access this way :

$_COOKIE['minutes']

People are also looking for solutions to the problem: Why does my Php Image upload not work?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.