Support » Fixing WordPress » Using PHP Sessions in WordPress

  • Resolved Peter Wooster


    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

    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()) {
    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.


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.