WordPress.org

Support

Support » Plugins and Hacks » Okay to use $_SESSION in plugins?

Okay to use $_SESSION in plugins?

  • In the process of creating a plugin, I needed to use a $_SESSION in order to save info but I noticed that session_start() is not used in WordPress.

    So I started to think that WordPress does not want you to use $_SESSION. If this is the case, what is the proper way to go about doing something equivalent.

    If it’s okay to use $_SESSION, should I put the session_star() in wp-config.php or in the plugin itself?

    Sorry in advance for being a WordPress newbie but hopefully I’ll be able to repay the community in the future when I get a hang of this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • WordPress DOES use session start…. either that or it was me that did it…

    Either way, I’ve used it and it will work fine. Mine is in my header.php file. Since that’s loaded first (before the rest of my stuff anyway) and my plugin is a content filter, I can use session variables in my plugin without starting the session there (since it was already started in my header).

    So far, no problems. You can always try it an see. In fact, try this:

    Before you add anything, put a print_r($_SESSION) statement in your code to see if there’s already a session running. If you can print session variables from your plugin, then you can use them there.

    Thanks jeremyduffy. I put the session_start() at the start of my plugin and it works fine but without it, it doesn’t work. In any case, it’s all good.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Okay to use $_SESSION in plugins?’ is closed to new replies.
Skip to toolbar