Using PHP Sessions in WordPress
-
I’ve spent a bit of time sorting out the use of PHP sessions in WordPress. I’ve posted a discussion of the issues on my blog at https://devondev.com/2012/02/03/using-the-php-session-in-wordpress/
For those who just want the bottom line here it is. Put the following code in your plugin or theme code:
add_action('init', 'myStartSession', 1); add_action('wp_logout', 'myEndSession'); add_action('wp_login', 'myEndSession'); function myStartSession() { if(!session_id()) { session_start(); } } function myEndSession() { session_destroy (); }
Do not put the session_start in wp-config.php if there is any chance that register_globals is set in your PHP system.
/peter
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Using PHP Sessions in WordPress’ is closed to new replies.