A
A
Aricus2020-06-03 16:17:55
PHP
Aricus, 2020-06-03 16:17:55

Why is session_id reset in wordpress site?

There is a site on wordpress (I don't know if it matters). Previously, everything was in order, but suddenly sessions began to act up: data between pages was not saved. The study showed that the session_id is reset (each time a new one when the page is updated):
var_dump(session_id());
at the same time, session files are also created new each time, and the old ones are not deleted.
Moreover, this bug is unstable: it can disappear and appear when changing pieces of code that are not directly related to sessions. For example, at one time adding this piece of code to functions.php worked, and I have no idea why (It definitely helped: I checked it on different browsers. If you remove this piece and open it on a new browser or computer, the bug returned. If you add it again, it starts Remove again and open on an already used browser - it did not stop working):

if (!isset($_SESSION["test2"])) {
  echo '<script></script>';
    $_SESSION["test2"] = 1;
}

Sessions are initiated from above functions.php like so (domain behind***):
ini_set('session.cookie_domain', '***.***.ru');
ini_set('session.use_trans_sid', 1);
session_set_cookie_params(36000, "/", "***.***.ru", false, false);
session_start();

The first two lines helped people with the same problem. They didn't help me.
Also worth noting:
  • The error occurs in all major browsers, under the most common page refresh conditions. No ajax, no redirects, no cookies in the browser.
  • session_destroy is nowhere in the site theme. I can't vouch for wordpress core.
  • favicon.ico (they say its absence can lead to this error) is formed on the site by wordpress (in the appearance settings by loading a large png image).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-06-03
@FanatPHP

There was a big high on this topic recently on reddit.
From it, I learned that
1. there is at least 1 special WordPress hosting that kills PHP sessions
2. WordPress does not use PHP sessions, you are not advised
3. if your WordPress site uses sessions, it means you are using a plug-in from shit code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question