简体   繁体   中英

PHP proper use of session_start

When the web app starts, it will connect to DB and store the information as sessions variables. To get only the data at the beginning of the application.

The problem is that the users list is also a session variable. So in the login.php I have to add session_start() again when the user put the correct username and password?

I think my solution is:

- Web server run -> session_start() and get all the data needed.

- When the client run the app, there's no user logged in therefore the index.php will redirect to login.php. No session_start() because it as already started and after the correct username and password, change session variable "username" or "ID" to the username logged in.

- When the client log out, unset session variable "username".

What do you think about this solution, is this a right use of session in PHP?

一旦启动会话,则无需再次启动它,只需使用此会话来保存数据并检查登录,它将起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM