title

Setting Up Sessions In WordPress

 

Setting Up Sessions In WordPress

23 Oct 2013, Posted by antoine in

Sessions are great for storing information between pages and are widely used on websites. WordPress doesn’t use them at all internally, so the session is never set. Using the following method, you can start a session on all pages before any output.

add_action( 'init', 'smashing_session_start' );
function smashing_session_start() {
if ( !session_id() ) {
session_start();
}
}

Note that, while sessions are generally pretty safe, implement IP checking or added nonce protection just to be on the safe side. As long as you’re transmitting non-sensitive data, though, you’ll fine. Check out Mark J. Aquith’s great article on nonces for more info.