Home > Blockchain >  WP SESSION - Ends Very Fast
WP SESSION - Ends Very Fast

Time:05-31

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.

CodePudding user response:

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

CodePudding user response:

"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 )

  • Related