user1978592 user1978592 - 5 days ago 5
PHP Question

How do you use session variables in wordpress?

I have the following plugin: http://wordpress.org/support/plugin/wp-session-manager

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?

Thanks.

Answer

Replace:

global $wp_session;

With:

$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.

Comments