Using Sessions in WordPress
0March 13, 2012 by Al
WordPress does not use sessions to hold data. It is a stateless application. This means that if you want to use sessions in your plugins or custom modifications of WordPress, you may need to do a little hack to enable sessions.
Edit your wp-config.php file (located at the root of your blog) and add the following line at the beginning of the file:
if (!session_id())
{
session_start();
}
Now you can use sessions in WordPress. Remember that for most plugins, instead of using sessions to store data you can pass variables in URLs and hidden fields or use cookies, and that is what WordPress encourages.
or
Here’s a simple function you can add in your functions.php file that will start a session automatically. Then you don’t need the wp-config.php session_start(); code.
function cp_admin_init() {
if (!session_id())
session_start();
}
add_action(‘init’, ‘cp_admin_init’);
from http://diovo.com/2009/10/using-sessions-in-wordpress/
see also: http://devondev.com/2012/02/03/using-the-php-session-in-wordpress/
Category Technology | Tags:
0 comments
Sorry, comments are closed.