When to start a session?

后端 未结 6 1632
你的背包
你的背包 2021-01-16 14:28

I have a system that requires the user to login (or register) for an account before they are able to access their Member \'dashboard\'.

My question is... at what poi

相关标签:
6条回答
  • 2021-01-16 15:04

    As Helge Helwig said,

    you need to add session_start() in the top of every page. However, to make this easier, you can create a PHP document, where you store all vital code like this, and call it; say init.php.

    Then you can include 'init.php' at the top of every page, which would clean up the code a bit.

    0 讨论(0)
  • 2021-01-16 15:06

    You need to include session_start() on every page where you want the session data to be accessible. And it needs to be called before any other output has been done.

    0 讨论(0)
  • 2021-01-16 15:06

    Start a session on the page(s) that need to access session data. As part of a successful login, you should also call session_regenerate_id to prevent session fixation.

    0 讨论(0)
  • 2021-01-16 15:13

    You should start session after verifying user's information, and than you can set user's uid to session variable. which could be useful afterwards in loading user's personal information like profile,preferences etc.

    on register page i think you do not need to start session.

    Regards

    0 讨论(0)
  • 2021-01-16 15:19

    you can start session once user is authenticated. after that you can user related information in S_SESSION and access this info from anywhere.

    0 讨论(0)
  • 2021-01-16 15:28

    Your session_start() will be called on each and every page that is secure and that is accessed after authentication. You will put the values in session both in login and register pages as they authenticate user. But once the user is verified, now you have to put this function on all pages which needs authentication of the user.

    0 讨论(0)
提交回复
热议问题