Title: Remove session_start() Dependency
Last modified: March 17, 2017

---

# Remove session_start() Dependency

 *  Resolved [adamchal](https://wordpress.org/support/users/adamchal/)
 * (@adamchal)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/remove-session_start-dependency/)
 * Recently I noticed hundreds of thousands of empty sessions on our server. I finally
   traced the culprit to line 15 of **class-wc-rejoiner.php**:
 *     ```
       class WC_Rejoiner extends WC_Integration {
   
           public function __construct() {
   
               session_start(); // <-- line 15
               $this->sess = session_id();
       ```
   
 * It looks like the plugin is creating an empty session just to set a cookie and
   get a unique token. But, no data is ever saved to the PHP session. The Rejoiner
   data is saved to a WP `_transient_rjcart_[session token]` row.
 * [@madjax](https://wordpress.org/support/users/madjax/): I would like to offer
   the following alternatives to creating empty PHP native sessions:
    1. Leverage WooCommerce’s internal cart/session to save this Rejoiner data;
    2. Or, if this is not a viable solution, then use `setcookie()` or `wp_setcookie()`
       to create a random cookie to act as your session token. You could also allow
       these cookie properties (name, domain, ttl, etc.) to be configurable in the 
       plugin settings page.
 * Either of these approaches would eliminate the dependency on native PHP sessions
   and would prevent the creation of thousands of empty sessions.
 * I’m happy to assist or provide more clarity if you’d like.
 * Thanks,
    Adam

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

 *  Plugin Author [Jackson Whelan](https://wordpress.org/support/users/madjax/)
 * (@madjax)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-8936221)
 * Thanks for the info, I’ll review and update you here.
 * Is garbage collection not working on your server?
 *  Thread Starter [adamchal](https://wordpress.org/support/users/adamchal/)
 * (@adamchal)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-8936354)
 * Hey [@madjax](https://wordpress.org/support/users/madjax/), garbage collection
   is working, but it’s configured with a 30 day TTL. In that time, we accumulate
   over 300k empty sessions. We’re using a memcache session store in php.ini, so
   these empty sessions just waste memory. I recently ran a job that cleared out
   these empty sessions, but then I realized that I’m breaking your plugin since`
   session_start()` will generate a new session/cookie if it is not found in memcache.
 * I think using your own cookie with wp-admin configurable options, or piggy-backing
   on WooCommerce’s internal cart/session should be a better approach.
 *  Thread Starter [adamchal](https://wordpress.org/support/users/adamchal/)
 * (@adamchal)
 * [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9142670)
 * Hi [@madjax](https://wordpress.org/support/users/madjax/), have you given this
   any more thought?
 *  Plugin Author [Jackson Whelan](https://wordpress.org/support/users/madjax/)
 * (@madjax)
 * [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9157956)
 * Hi [@adamchal](https://wordpress.org/support/users/adamchal/), sorry lost track
   of this in the midst of a cross country move. Can you try this release and let
   me know what you think : [https://www.dropbox.com/s/bdvxs3ak6w3q73v/woocommerce-rejoiner.zip?dl=0](https://www.dropbox.com/s/bdvxs3ak6w3q73v/woocommerce-rejoiner.zip?dl=0)
   Thanks!
 *  Thread Starter [adamchal](https://wordpress.org/support/users/adamchal/)
 * (@adamchal)
 * [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9160721)
 * Hey [@madjax](https://wordpress.org/support/users/madjax/), this is perfect. 
   Much love for this. Thanks a lot!
 *  Plugin Author [Jackson Whelan](https://wordpress.org/support/users/madjax/)
 * (@madjax)
 * [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9160852)
 * [@adamchal](https://wordpress.org/support/users/adamchal/) glad to hear it. Can
   you report back in a week and let me know if you’re still loving it?
 *  Thread Starter [adamchal](https://wordpress.org/support/users/adamchal/)
 * (@adamchal)
 * [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9160880)
 * [@madjax](https://wordpress.org/support/users/madjax/), will do.
 *  Thread Starter [adamchal](https://wordpress.org/support/users/adamchal/)
 * (@adamchal)
 * [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9180926)
 * Hey [@madjax](https://wordpress.org/support/users/madjax/), just following up…
   this is still working great!
 *  Plugin Author [Jackson Whelan](https://wordpress.org/support/users/madjax/)
 * (@madjax)
 * [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9183593)
 * Thanks [@adamchal](https://wordpress.org/support/users/adamchal/), just committed
   the changes. Appreciate your report.

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

The topic ‘Remove session_start() Dependency’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-rejoiner/assets/icon-256x256.png?rev=3039457)
 * [Rejoiner for WooCommerce](https://wordpress.org/plugins/woocommerce-rejoiner/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-rejoiner/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-rejoiner/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-rejoiner/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-rejoiner/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-rejoiner/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [Jackson Whelan](https://wordpress.org/support/users/madjax/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/remove-session_start-dependency/#post-9183593)
 * Status: resolved