Flickr

This is a test post from flickr, a fancy photo sharing thing.

wordpress and session variables

I was surprised when I found out that wordpress doesn’t allow sessions by default. I searched for many workarounds, took one whole day to figure out. Now I was developing a plugin, which needed to store some temporary data in session, so I had to enable session variables to be available on every page of the plugin.

What you need to do is very simple. Add the following line of code in wp-config.php.

if(!isset(session_id()))
  session_start();

and then include this in your plugin page, this is the bootstrap file which has all the settings (makes call to wp-settings and wp-config file which contains all the settings)

require_once('../../../wp-load.php'); //path to wp-load.php

bingo!, you have enabled sessions to work with your plugins!

Next Page →