Title: Issue with session_start
Last modified: May 8, 2019

---

# Issue with session_start

 *  Resolved [oliverhtml](https://wordpress.org/support/users/oliverhtml/)
 * (@oliverhtml)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/)
 * Hi there,
    I’ve had an issue with this plugin and redis caching on krystal hosting’s
   onyx hosting. When a request is sent to wp-ajax it raises a headers already sent
   warning originating in the plugin on this section, this then causes redis to 
   break for some unknown reason and ajax then returns a 500 error. I’ve disabled
   all other plugins and the theme and narrowed it down to this line.
 * if (!session_id()) {
    session_start(); }
 * When I comment out the session_start the whole thing works quite nicely, this
   occurs on php 7.3. I suspect there’s not that much you can do as I’ve had a little
   look and the session id is always returning as false in my instance.
 * Thanks,
    Oliver

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

 *  Plugin Author [apasionados](https://wordpress.org/support/users/apasionados/)
 * (@apasionados)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11510231)
 * Hi [@oliverhtml](https://wordpress.org/support/users/oliverhtml/),
 * Sorry to hear that you are having problems. I don’t think we can fix them, but
   we will have a look.
 * Best regards from Spain.
 *  Thread Starter [oliverhtml](https://wordpress.org/support/users/oliverhtml/)
 * (@oliverhtml)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11516754)
 * Hi there,
    it turns out that this is the cause of the intermittent 502 errors
   we’ve been seeing also. Could you check for one of the redis constants: WP_REDIS_PORT,
   WP_REDIS_HOST, WP_REDIS_PASSWORD prior to a session_start call or provide a filter
   that returns whether or not to start a session. I’m conscious that we still want
   to use the plugin but don’t want to take it off of the update path!
 * Kind Regards,
    Oliver
 *  Plugin Author [apasionados](https://wordpress.org/support/users/apasionados/)
 * (@apasionados)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11516840)
 * Hi [@oliverhtml](https://wordpress.org/support/users/oliverhtml/),
 * If you have modified the plugin with the constants, please share the changes 
   and we will test them to include them in the plugin reléase.
 * Best regards from Spain.
 *  Thread Starter [oliverhtml](https://wordpress.org/support/users/oliverhtml/)
 * (@oliverhtml)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11516949)
 * Hi,
    this seems to do it for compatability with this plugin: [https://wordpress.org/plugins/redis-cache/](https://wordpress.org/plugins/redis-cache/)
 * it’s probably not the best solution overall as it’s specific to that plugin but
   it does get it running on krystal hosting’s onyx package.
 * if (!session_id()) {
    if(empty(WP_REDIS_HOST) && empty(WP_REDIS_PORT) && empty(
   WP_REDIS_PASSWORD)){ session_start(); } }
 * Thanks,
    Oliver
 *  Plugin Author [apasionados](https://wordpress.org/support/users/apasionados/)
 * (@apasionados)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11517404)
 * Thanks for the code. Probably we will modify it before our tests to check whether
   the variable exists with `!isset(WP_REDIS_HOST)` instead of `empty(WP_REDIS_HOST)`
   to avoid errors when the variables are not defined.
 * `!isset(WP_REDIS_HOST)` to check whether a variable is not set.
 * `empty(WP_REDIS_HOST)` works for:
    - “” (an empty string)
    - 0 (0 as an integer)
    - 0.0 (0 as a float)
    - “0” (0 as a string)
    - NULL
    - FALSE
    - array() (an empty array)
    - $var; (a variable declared, but without a value)
 * But we are not sure how it behaves in different PHP versions when the variable
   is not defined.
 * Could you please try on your installation if this works for you:
 *     ```
       if (!session_id()) {
       if(!isset(WP_REDIS_HOST) && !isset(WP_REDIS_PORT) && !isset(WP_REDIS_PASSWORD)){
       session_start();
       }
       }
       ```
   
 * Best regards from Spain.
    -  This reply was modified 7 years, 1 month ago by [apasionados](https://wordpress.org/support/users/apasionados/).
      Reason: added code tag to empty(WP_REDIS_HOST)
 *  Thread Starter [oliverhtml](https://wordpress.org/support/users/oliverhtml/)
 * (@oliverhtml)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11517665)
 * Hi again!
    I just used empty because it checks whether the variable exists and
   is the equivalent of : !isset($var) || $var == false
 * [https://www.php.net/manual/en/function.empty.php](https://www.php.net/manual/en/function.empty.php)
 * I will update to your method and give it a go
    Thanks, Oliver
 *  Plugin Author [apasionados](https://wordpress.org/support/users/apasionados/)
 * (@apasionados)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11517747)
 * Ok. Looks like we were wrong and it’s better to use `empty`: _Determine whether
   a variable is considered to be empty. A variable is considered empty if it does
   not exist or if its value equals FALSE. empty() does not generate a warning if
   the variable does not exist._
 * So we will use empty() then.
 * Best regards from Spain.

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

The topic ‘Issue with session_start’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7-lead-info-with-country/assets/icon-128x128.
   png?rev=1043884)
 * [Lead info with country for Contact Form 7](https://wordpress.org/plugins/contact-form-7-lead-info-with-country/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-lead-info-with-country/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-lead-info-with-country/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-lead-info-with-country/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-lead-info-with-country/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-lead-info-with-country/reviews/)

## Tags

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

 * 7 replies
 * 2 participants
 * Last reply from: [apasionados](https://wordpress.org/support/users/apasionados/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/issue-with-session_start/#post-11517747)
 * Status: resolved