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):
global $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.
Session variables are special variables that exist only while the user's session with your application is active. Session variables are specific to each visitor to your site. They are used to store user-specific information that needs to be accessed by multiple pages in a web application.
WordPress Core does not use sessions. All "user state" is managed via cookies. This is a Core design decision. However, some plugins or themes will use session_start() or PHP's $_SESSION superglobal.
From your WordPress dashboardVisit 'Plugins > Add New'. Search for 'Sessions'. Click on the 'Install Now' button. Activate Sessions.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With