PHP $_SESSION in Wordpress
I was recently writing some code for an application based on Wordpress when I realised that I would need to retain data across pages. Naturally, I opted to use PHP session handling. A quick search for the string ‘_SESSION’ suggested that Wordpress does not use the $_SESSION superglobal array. Therefore, if you are going to simple user $_SESSION in your code, you will need to place session_start(); somewhere in the code, either in a core Wordpress include file, a plugin file or in a specific file(s).
Finally, if the session handling is used as part of the Wordpress administration backend, you will probably want to terminate the session when the user logs out. To achieve this, you can simply create a function that destroys the session and call this function during the ‘wp-logout’ hook.
function clear_session() {
session_destroy();
}add_action(’wp_logout’, ‘clear_session’);
Tags: PHP Session, Wordpress

















































