Wordpress $ _SESSION does not work even after adding add_action ('init,' ... ', 1)

I am trying to get SESSION to work with Wordpress, but it cannot work, even I added the code below to my plugin, but nothing happens:

add_action('init', 'simpleSessionStart', 1); add_action('wp_logout', 'simpleSessionDestroy'); add_action('wp_login', 'simpleSessionDestroy'); function simpleSessionStart() { if(!session_id())session_start(); } function simpleSessionDestroy() { session_destroy (); } 

How can I make the transfer date of $ _SESSION from one page to another on my wordpress site

My Wordpress Version: 3.5.2

My theme: twentyeleven

+4
source share
2 answers

Put this code in functions.php file

 function sess_start() { if (!session_id()) session_start(); } add_action('init','sess_start'); 
+8
source

See this answer for a discussion of using $_SESSION in WordPress. In short, WordPress removes session variables if register_globals defined.

Comments on the question itself point to this answer on WordPress stackexchange, which discusses a plugin that can help you.

+3
source

Source: https://habr.com/ru/post/1494607/


All Articles