sylvest Posted February 27, 2020 Posted February 27, 2020 I'm having a problem on a website that I develop. It seems that sometimes when I call session_start(), it fails to find a previously opened session, and opens a new one, which means that I lose all my session variables. Here's a section of log: [27-Feb-2020 17:39:43.496 GMT 0] on localhost, L_TRACE MemberId 18 attempted to login with PasswordStatus = 4 at line 169 in file: /home/sylvest/public_html/swchoir/do_login.php [27-Feb-2020 17:39:43.497 GMT 0] on localhost, L_TRACE Session ID = qdgs4obtlicrlcgnp6tc179e87, $_SESSION = {"breadcrumbs":[{"shortname":"Login", "filename":"index.php"}], "request_index":2, "test_mode":0, "username_entered":"sasb", "login_member":null, "login_memberid":"18", "login_name":"Sue Sylvester-Bradley", "auth_level":0, "return_page":"\/swchoir\/do_login.php", "edit_member_msg":"Your password has expired, and you need to choose a new one before you can access these pages. Please do that now.", "edit_memberid":"18", "edit_member_mode":"change_password"} at line 319 in file: /home/sylvest/public_html/swchoir/do_login.php [27-Feb-2020 17:39:43.497 GMT 0] on localhost, L_TRACE Send cookie username_entered:sasb succeeded at line 334 in file: /home/sylvest/public_html/swchoir/do_login.php [27-Feb-2020 17:39:43.497 GMT 0] on localhost, L_TRACE $to_page = edit_member.php?v=1582819873 at line 1200 in file: /home/sylvest/include/functions.php Called from redirect(edit_member.php?v=1582819873) at line 339 in file /home/sylvest/public_html/swchoir/do_login.php [27-Feb-2020 17:39:43.497 GMT 0] on localhost, L_TRACE Redirecting to Location: https://sylvesterbradley.org/swchoir/edit_member.php?v=1582819873 using header at line 1201 in file: /home/sylvest/include/functions.php Called from redirect(edit_member.php?v=1582819873) at line 339 in file /home/sylvest/public_html/swchoir/do_login.php [27-Feb-2020 17:39:43.817 GMT 0] on L_TRACE Started file at line 37 in file: /home/sylvest/public_html/swchoir/edit_member.php [27-Feb-2020 17:39:43.817 GMT 0] on L_TRACE Started file at line 5 in file: /home/sylvest/include/basic_init.php [27-Feb-2020 17:39:43.817 GMT 0] on L_TRACE Started file at line 4 in file: /home/sylvest/include/functions.php [27-Feb-2020 17:39:43.817 GMT 0] on L_TRACE Started file at line 13 in file: /home/sylvest/include/log_functions.php [27-Feb-2020 17:39:43.818 GMT 0] on , L_TRACE Resumed file at line 9 in file: /home/sylvest/include/functions.php Called from require_once(/home/sylvest/include/functions.php) at line 129 in file /home/sylvest/include/basic_init.php Called from require(/home/sylvest/include/basic_init.php) at line 128 in file /home/sylvest/public_html/swchoir/edit_member.php [27-Feb-2020 17:39:43.818 GMT 0] on , L_TRACE Resumed file at line 140 in file: /home/sylvest/include/basic_init.php Called from require(/home/sylvest/include/basic_init.php) at line 128 in file /home/sylvest/public_html/swchoir/edit_member.php [27-Feb-2020 17:39:43.818 GMT 0] on , L_TRACE session_status() = PHP_SESSION_NONE at line 782 in file: /home/sylvest/include/functions.php Called from my_session_start() at line 152 in file /home/sylvest/include/basic_init.php Called from require(/home/sylvest/include/basic_init.php) at line 128 in file /home/sylvest/public_html/swchoir/edit_member.php [27-Feb-2020 17:39:43.818 GMT 0] on , L_TRACE No session is active at line 789 in file: /home/sylvest/include/functions.php Called from my_session_start() at line 152 in file /home/sylvest/include/basic_init.php Called from require(/home/sylvest/include/basic_init.php) at line 128 in file /home/sylvest/public_html/swchoir/edit_member.php [27-Feb-2020 17:39:43.819 GMT 0] on , L_TRACE Session ID 5ks74rcukqqbkjdhchiru310q3 is now active, RemoteIp = 90.251.34.221 at line 804 in file: /home/sylvest/include/functions.php Called from my_session_start() at line 152 in file /home/sylvest/include/basic_init.php Called from require(/home/sylvest/include/basic_init.php) at line 128 in file /home/sylvest/public_html/swchoir/edit_member.php [27-Feb-2020 17:39:43.819 GMT 0] on , L_TRACE Session ID = 5ks74rcukqqbkjdhchiru310q3, $_SESSION = [] at line 805 in file: /home/sylvest/include/functions.php Called from my_session_start() at line 152 in file /home/sylvest/include/basic_init.php Called from require(/home/sylvest/include/basic_init.php) at line 128 in file /home/sylvest/public_html/swchoir/edit_member.php In the first bolded section, you can see that session ID qdgs4obtlicrlcgnp6tc179e87 is active, and that there are all sorts of session variables set. In the second bolded session, session_status() returned PHP_SESSION_NONE, so when I called session_start() it created a new session 5ks74rcukqqbkjdhchiru310q3 and all my session variables have gone. What am I doing that is causing the session to be lost? How do I make sure that when I call session_start() it retrieves any previous session if there is one, and does not create a new one? Can I implement my own version of session_start() and thus see exactly what it is doing and put in logic to prevent this error? What exactly does session_start() do? Thank you - Rowan , Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.