How do you use session variables in wordpress?
- Add below code in
function.php
file
function register_my_session(){ if( ! session_id() ) { session_start(); } } add_action('init', 'register_my_session');
- After that you can store value in session variable like
$_SESSION['something'] = $xyz
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.