简体   繁体   中英

How many session variables can I use in one session_start in PHP?

I have multiple session variables. How many times do I have to call session_start in a page? If only once, is it going to account for four session variables eg $_SESSION['a'],$_SESSION['login'],$_SESSION['b'],$_SESSION['c'] ?

You only need to call session_start once. It will account for all of your $_SESSION variables.

Within the session, you can have practically as many session variables as you like.

Best practice is to call session_start at the top of your script, before any output is generated.

To use the session you need to call session_start() before using $_SESSION variables. To avoid errors like

Cannot modify header information - headers already sent (..)

call session_start() on the very top of your script.

By default the maximum size of the session is the maximum memory of your script - 128mb . For further information this SO question .

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