WordPress – Enable PHP Session

Add the following code under the top PHP opening tag of wp-config.php.

<?php
  if (!session_id()) {
    session_start();
  }
...

We can now make use of the $_SESSION[] in WordPress. The reason of putting the session_start() in wp-config.php is because this configuration file will not be overwritten during a WordPress update.

Thanks Frank Verhoeven.

Done =)

Reference: Frank Verhoeven – Using Sessions in WordPress

Updated @ 2012-08-02: Please note that their maybe security issue of using the PHP session. For more information, please refer to the following link.
PHP $_SESSION variables

8 thoughts on “WordPress – Enable PHP Session”

  1. hi i have tried this as wella s putting it in the functions.php, as well as adding it to the wp_unregister_globals array….but none seems to work for me .Instead they crash my website i end up getting a blank screen. Everything reverts to normal when i remove it from the config.php or functions.php

    Like

    1. What wordpress version are u using?

      Have you tried to add it to wp-config.php instead of config.php and functions.php?

      Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.