PHP SESSION data lost between page loads with WAMPserver 2.0 on localhost

后端 未结 7 983
长情又很酷
长情又很酷 2021-01-15 02:08

I have a PHP authentication system on my website using the $_SESSION variable.

A form submits a username and password to the file \"login.php\". It is handled like t

7条回答
  •  萌比男神i
    2021-01-15 02:44

    First of all: the index logedin seems strange for keeping track of a user being logged in. Is this just a typo on SO, or really a code-typo?

    Second (depending on the desired behavior), try another approach for making pages login-protected. Your page should look something like

    
        // put some plain HTML here  
        
    

    Where login.inc.php handles the session, cookies. In particular, the authorized function should return TRUE if a client is already logged in. If a client is not logged in, it should display a form with action $_SERVER['PHP_SELF'] and return FALSE. If you name the submit-input something like login_submit, you can let login.inc.php handle the verification.

    This way, you don't need to refer users to a dedicated login page, and after logging in, user are directly shown the requested page. You can tweak this a bit to make query-strings persistent through login as well.

提交回复
热议问题