Get current session in WP admin

Trying to access sessions in the WP admin and access a variable from it.

function tasks_admin_sessions() {
    if(!session_id()) {
        session_start();
    }
}
add_action( 'admin_init', 'tasks_admin_sessions', 1 );

$nonce = $_session['wp_nonce']
$completed_url = admin_url( "post.php?post=$post_idaction=trash_wpnonce=$nonce" );

but I get:

Notice: Undefined variable: _session

What am I missing in my code to get the session variables?

Topic admin-init session wp-admin Wordpress

Category Web


Google is your friend. How to use session_start in Wordpress? and How to use session in wordpress in plugin development

It looks like your mistake is that you didn't capitalise "Session" when you declare the variable.

Instead of $_session['wp_nonce'], try $_SESSION['wp_nonce'].

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.