Title: Using PHP Sessions in WordPress
Last modified: August 20, 2016

---

# Using PHP Sessions in WordPress

 *  Resolved [Peter Wooster](https://wordpress.org/support/users/pkwooster/)
 * (@pkwooster)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/using-session-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 [http://devondev.com/2012/02/03/using-the-php-session-in-wordpress/](http://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)

 *  Thread Starter [Peter Wooster](https://wordpress.org/support/users/pkwooster/)
 * (@pkwooster)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/using-session-in-wordpress/#post-2551168)
 * I have published this code as plugin [Simple Session Support](http://wordpress.org/extend/plugins/simple-session-support/).
 * There are other session plugins out there, but they do not clean up at logout.
   /
   peter
 *  [Kishores](https://wordpress.org/support/users/kishores/)
 * (@kishores)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/using-session-in-wordpress/#post-2551241)
 * My php session unset due to wp_head()in header.php.My session works fine without
   wp_head(). Is there any conflict between session and wp_head?
 *  [screets](https://wordpress.org/support/users/beytar/)
 * (@beytar)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/using-session-in-wordpress/#post-2551264)
 * There is a powerful plugin for sessions here: [WP Sessions Plugin](http://codecanyon.net/item/wordpress-sessions-plugin-with-database/3405722)
 *  Thread Starter [Peter Wooster](https://wordpress.org/support/users/pkwooster/)
 * (@pkwooster)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/using-session-in-wordpress/#post-2551265)
 * That looks like a useful plugin for those who need all that functionality. However
   it is a CodeCanyon premium plugin and as such doesn’t belong here.
 *  [lubchik](https://wordpress.org/support/users/lubchik/)
 * (@lubchik)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/using-session-in-wordpress/#post-2551269)
 * Thank you!!! I was really helpful!
 *  [tcreary](https://wordpress.org/support/users/tcreary/)
 * (@tcreary)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/using-session-in-wordpress/#post-2551272)
 * I installed and activated the plugin but I cannot pass $_SESSION variables yet.
   Is there anything else required to initiate the add_action function?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Using PHP Sessions in WordPress’ is closed to new replies.

## Tags

 * [development](https://wordpress.org/support/topic-tag/development/)
 * [session](https://wordpress.org/support/topic-tag/session/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 5 participants
 * Last reply from: [tcreary](https://wordpress.org/support/users/tcreary/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/using-session-in-wordpress/#post-2551272)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
