Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im using a wfcart in my WordPress site but for some reason on certain pages WordPress drops the session I'm wondering if there is a way to enable sessions in WordPress 3?

share|improve this question
    
None of the answers seem to work with wordpress 3.0.5 on my side. –  Cawas Feb 17 '11 at 21:26
    
So I solved it by replacing sessions by form and serialize: stackoverflow.com/questions/1719087/… –  Cawas Feb 21 '11 at 19:23
    
Better solution here: wordpress.stackexchange.com/a/72744/20261 –  dino Nov 16 '12 at 13:55

2 Answers 2

up vote 4 down vote accepted

If you need to manually enable the session globally, use this in your functions.php (I included a line for manually setting a session variable as an example, not required):

add_action('init', 'session_manager');
function session_manager() {
    if (!session_id()) {
        session_start();
    }
    $_SESSION['foo'] = 'bar';
}

and if you wanted to manually clear the session on an event (like logging out):

add_action('wp_logout', 'session_logout');
function session_logout() {
        session_destroy();
}
share|improve this answer
1  
I tried this, but not working for me. –  Arpita Nov 18 '10 at 6:12

As an addition to Somatic's reply, note that sessions can prevent you from scaling when misconfigured.

Specifically, if your site spans more than one server, be sure to use one of the built-in Memcached save handlers from pecl, or an SQL-based session handler. And if you opt for an SQL handler written in php, be sure to use row-locking if your app involves any Ajax.

Not doing so and sticking to the filesystem handler, you may end up losing sessions based on which server gets hit by end users.

share|improve this answer
    
thanks for covering that end ;-) –  somatic Oct 20 '10 at 20:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.