How do I share a PHP variable between multiple pages?

后端 未结 5 699
离开以前
离开以前 2020-12-20 09:36

The idea/goal:

I have a username and password inside a text file on my computer. The form on the index page allows the user to sign in with their us

5条回答
  •  被撕碎了的回忆
    2020-12-20 09:59

    You can start a session and put the form values into the $_SESSION variable, which will be available on all pages.

    // On the page where your form is submitted:
    session_start();
    $_SESSION['name'] = $_POST['name'];
    
    // On the page where the user is redirected:
    session_start();
    echo $_SESSION['name'];
    

    Note that in reality you would probably want to include some form validation too!

提交回复
热议问题