How do I share a PHP variable between multiple pages?

后端 未结 5 684
离开以前
离开以前 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 10:25

    Use $_SESSION -!

    session_start();
    $_SESSION['username'] = $_POST['username'];
    

    You of course want to filter/sanitize/validate your $_POST data, but that is outside of the scope of this question...

    As long as you call session_start(); before you use $_SESSION - the values in the $_SESSION array will persist across pages until the user closes the browser.

    If you want to end the session before that, like in a logout button --- use session_destroy()

提交回复
热议问题