PHP Sessions: Explanation please?

前端 未结 2 1200
说谎
说谎 2020-12-11 12:57

I have been learning PHP for a little bit now, and it has been going really easy for the most part. The only thing I\'m hung up on is getting sessions to work. Google has be

相关标签:
2条回答
  • 2020-12-11 13:37

    It looks like you're not using session_start() in your main_login.php like etranger alluded to. You need to call that function at the start of each new request to begin using sessions.

    Otherwise, if you are calling session_start() and you just neglected to show it in the code sample, then maybe the session ID is being lost during the redirect. Are you using cookie-based sessions or passing session ID as a URL parameter? Try printing session_id() or SID at the top of each page. This will let you know when the session is lost (the session ID will change or be "").

    If you're using cookie-based sessions, then maybe the cookie is getting lost for some reason. If you're using URL parameter to pass session ID, then maybe transparent session ID support isn't working right.

    0 讨论(0)
  • 2020-12-11 13:37

    You have to call session_start() as early as possible, and definitely before using $_SESSION, which would otherwise be empty.

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