skip to Main Content

I have my own PHP file in WP Theme dir.
In the beginning of the file I use this line:

require_once(rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/wp-load.php');

This allows me to load Sessions. All script is finished. I did a lot of work. But just now notices, that this Session ends quite fast. I didn’t delete Session or do something like that. Why does WP close my Sessions? What to do, that these Sessions will be alive always until I will delete them? THANK YOU.

2

Answers


  1. First of all, take a look at php.ini. Do you have a value for session.cookie_lifetime? If not, then the session ends when the browser closes. If you have 0, then you have the same behavior. So, set the number of seconds you intend the session to be alive, see more here: https://www.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime

    Login or Signup to reply.
  2. "I have my own PHP file in WP Theme dir"

    so, you load WordPress inside WordPress?

    When you call your domain https://example.com wordpress starts to load all files, include your theme. When you try to load wp-load.php inside your theme file, you try to load WordPress a second time.

    you don’t need this include for session access.

    WordPress frontend doesn’t create session ( except login or woocommerce )

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search