I heard my friend say that I don't have to use session_start()
to use $_SESSION
in PHP? Is that true? If yes, how do I make it work? If I remove session_start()
from my code, I can no longer get $_SESSION
to work.
Yes it is possible not to have session_start()
calls on top of every page necessarily when you want to work with sessions. Thats the job of session autostart. If you set your session to auto start you can avoid those calls, otherwise you must.
session.auto_start boolean
session.auto_start specifies whether the session module starts a session automatically on request startup. Defaults to 0 (disabled).
So if you set session.auto_start
to 1 in your php configuration, you wont need to start session manually.
PS: It is working fine for your friend and not for you because he/she has enabled session.auto_start
and you haven't touched it and by default it is disabled.
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.