user1978592 user1978592 - 1 year ago 78
PHP Question

How do you use session variables in wordpress?

I have the following plugin:

I cannot work out how to use the session variables in WordPress. From what I understand by reading, this is how it should be used:

I have the following on page one (page 1):

gloabl $wp_session;
$wp_session['loggedIn'] = 15;

echo $wp_session['loggedIn'];

On the first page, the session variable is working but on the second page, the session variable is not working.
Can anyone suggest me where I am going wrong?


Answer Source


global $wp_session;


$wp_session = WP_Session::get_instance();

Make sure you add $wp_session = WP_Session::get_instance(); before you try to echo the variable on page 2.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download