0

I'm having an issue on my website I can't seem to troubleshoot. The site has a login that works fine, but the site sporadically logs users out.

Steps: 1. Login

  1. Use site (usually won't log you out right away)

  2. Click on link (The links vary, doesn't seem to be isolated to a specific one)

  3. Get logged out

The site has a 60-90 minute timer that is supposed to log people out, but for some reason I keep getting booted 5-30 minutes in. I have an MySQL_error function that reports errors but it doesn't report an error being present (otherwise I would post it). This error has been present for quite a while and I can't figure out how to troubleshoot it very well at all. I would be very grateful for any assistance!

All of my pages use $_SESSION like so....

if(isset($_SESSION['user_id'])) { insert page coding here }

Else it logs you out. I have noted this abnormality on multiple computers and I don't think it's based on my computer settings.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Xukusari
  • 1
  • 2
  • 1
    Have you tried enabling php error logs and see if it is throwing any errors ? – d_void Oct 01 '17 at 22:54
  • What is the value of `session.gc_maxlifetime` in your php.ini? You can see it with `phpinfo()` also. – ishegg Oct 01 '17 at 22:57
  • I've looked at the php error logs and there haven't been any errors in the last few months. HOWEVER, previously it would throw an error on header.php line 1 (which was literally just ). – Xukusari Oct 01 '17 at 22:58
  • ishegg here is your answer: session.gc_maxlifetime 1440 (local) 1440 (master) – Xukusari Oct 01 '17 at 23:02
  • Well, there's *your* answer :). Your sessions are being destroyed about every 24 minutes. You need to modify that value to make them last more. – ishegg Oct 01 '17 at 23:33
  • Hmm, do you know why someone would last longer than others though? It's erratic and not strictly every 24 minutes, I'll give this a try just want to see if there was any more clarification on the topic. – Xukusari Oct 01 '17 at 23:56

1 Answers1

0

I had a similar problem once (see php $_SESSION variables disappear and reappear randomly). It acted as if session variables would disappear randomly, and sometimes they also reappeared after some time.

I was eventually able to fix that problem by activating strict mode for sessions, adding this line right at the top of the page, above session_start();:

ini_set('session.use_strict_mode', 0);
Johannes
  • 64,305
  • 18
  • 73
  • 130
  • Johannes, I'm going to give ishegg's idea a try and if that doesn't work I'll definitely give your idea a try. The logout issue is fairly erratic so I might be back here unless everything clears up. – Xukusari Oct 01 '17 at 23:57
  • Hey Johannes just wanted you to know your method worked, ishegg's also helped but the issue kept coming up (just not as often). So not sure what what happened overall but it's resolved thanks to you two. – Xukusari Oct 02 '17 at 11:29