ElkArte Community

Elk Development => Bug Reports => Topic started by: Jorin on August 09, 2016, 11:13:21 am

Title: 1.0.9 loosing session
Post by: Jorin on August 09, 2016, 11:13:21 am
I installed 1.0.9 today and since then I often loose my session and I get logged out. A second user wrote me, he experienced the same.

Anyone around here with 1.0.9 and the same problem?
Title: Re: 1.0.9 loosing session
Post by: ahrasis on August 09, 2016, 12:37:25 pm
Not yet. I'll inform if there's any such a behaviour.
Title: Re: 1.0.9 loosing session
Post by: scripple on August 09, 2016, 02:39:06 pm
I haven't seen this problem with 1.0.8 or 1.0.9 except in conjunction with a mod I use.  Are you using any mods that alter the session or login information?  The function used to decode the cookie / session was changed so my code was failing to correctly pull out the time remaining before logout.  I updated to use the new function and it has been fine.
Title: Re: 1.0.9 loosing session
Post by: emanuele on August 09, 2016, 03:34:28 pm
With 1.0.9 the only change related to sessions is that the database entry of the session is updated at each page load.
If you told me that passing to 1.0.8 you had this problem I could understand, in 1.0.8 the session-related functions changed a bit and I even had some issues myself on my localhost.

So, check if the problem is 1.0.9 is rather easy: open the file sources/Session.php and find the line:
Code: [Select]
$_SESSION['mictrotime'] = microtime();
and remove it, or change it to:
Code: [Select]
// $_SESSION['mictrotime'] = microtime();
Title: Re: 1.0.9 loosing session
Post by: scripple on August 09, 2016, 08:55:57 pm
If you're asking me, yes my mod had the problem starting with 1.0.8.  Easy fix though.
Title: Re: 1.0.9 loosing session
Post by: Jorin on August 10, 2016, 01:08:57 am
Quote from: scripple – I haven't seen this problem with 1.0.8 or 1.0.9 except in conjunction with a mod I use.  Are you using any mods that alter the session or login information?

I don't think so. The mods I am using are:

AEVA BBCode replacement
AmazonAffiliate4ElkArte
Descriptive Links
Google Member Map
Inline Attachments
Recent Topics
Topic Author

Quote from: emanuele – So, check if the problem is 1.0.9 is rather easy: open the file sources/Session.php and find the line:
Code: [Select]
$_SESSION['mictrotime'] = microtime();
and remove it, or change it to:
Code: [Select]
// $_SESSION['mictrotime'] = microtime();

Done. What does this do? What should I look for now?
Title: Re: 1.0.9 loosing session
Post by: emanuele on August 10, 2016, 02:47:05 am
That bit does basically nothing.
The reason is there is that php 7 is become more strict on the returned values of the custom session handlers. Elk (and likely SMF) when writing a session does an UPDATE query, if the session data did not change, this result in a number of affected rows equal to zero, and the function returns false. At that point, the false means to php that the session failed to write and logs you out.
Using microtime, basically forces the UPDATE to always change the row in the database and return always true.

Well, you should look for not being logged out? ;)
Title: Re: 1.0.9 loosing session
Post by: Jorin on August 10, 2016, 02:50:18 am
Quote from: emanuele – Using microtime, basically forces the UPDATE to always change the row in the database and return always true.

Hm... Should microtime then not be active? I commented it out now?
Title: Re: 1.0.9 loosing session
Post by: emanuele on August 10, 2016, 03:11:54 am
I told you to remove it.

If you had problems with sessions starting from 1.0.9, this is the only change that affected sessions in that update, so it is the only candidate being the cause of the issue.
If removing it solves the issue, it means we need to find another way to fix php 7 without breaking other php versions.
Title: Re: 1.0.9 loosing session
Post by: Jorin on August 10, 2016, 03:17:28 am
I thought that removing (or commenting out) this line of code deactivates the microtime? Am I wrong?
Title: Re: 1.0.9 loosing session
Post by: emanuele on August 10, 2016, 05:35:21 am
Yes.
It does.
And it reverts back to the 1.0.8 behaviour, that according to your report was working fine.
Did I got it wrong?
Title: Re: 1.0.9 loosing session
Post by: Jorin on August 10, 2016, 05:45:09 am
I think not. I was just confused that I should activate microtime with deleting the line of code to do so.  ;)

Hm, maybe I am wrong and you want me to deactivate microtime instead? Will someone please kidnap me then?  :-[
Title: Re: 1.0.9 loosing session
Post by: emanuele on August 10, 2016, 06:28:33 am
Yes, I want to disable the change that was made, to see if the change is the cause of the error. ;)
Title: Re: 1.0.9 loosing session
Post by: Jorin on August 10, 2016, 06:39:21 am
I don't get it. lol The code is commented out. Let's see what happens.
Title: Re: 1.0.9 loosing session
Post by: ahrasis on August 10, 2016, 08:07:01 pm
For the time being, I think the code can be made conditional on php version. Maybe we can use php compare like this:

Code: [Select]
if (version_compare(phpversion(), '7.0.0', '>='))
 $_SESSION['mictrotime'] = microtime();
Title: Re: 1.0.9 loosing session
Post by: emanuele on August 11, 2016, 05:38:35 am
I'd prefer to understand where the problem is first. :)
One thing I forgot to ask @Jorin is: what version of php are you using?
/me assumed it's 5.x but it may be a wrong assumption
Title: Re: 1.0.9 loosing session
Post by: Jorin on August 11, 2016, 06:38:06 am
PHP 5.3.28.
Title: Re: 1.0.9 loosing session
Post by: emanuele on September 06, 2016, 06:06:44 am
Is this still happening?
Did you comment out the microtime string or not?
Title: Re: 1.0.9 loosing session
Post by: Jorin on September 12, 2016, 05:34:06 am
I did comment out. The problem seems to be gone. Never happened again after commenting out.