Support » Fixing WordPress » Sessions not working – Tried everything!

  • Resolved animalmutch


    I can’t get sessions to work. So far I have tried:

    1. Starting the session in wp-config.php
    2. Starting the session in functions.php
    3. Starting the session from within pages in my theme
    4. Starting the session from the main index page
    5. Adding _SESSION to the list of variables not to be unset by the wp_unregister_GLOBALS() function
    6. Adding specific session variable names to the list of variables not to be unset by the wp_unregister_GLOBALS() function
    7. Turning off register_globals in php.ini

    Sessions do work on some pages when I start the session in wp-config.php, functions.php and the main index page, but not in all pages, so I guess that the variables aren’t being unset, but that it’s a problem with the call to start the session. It seems that sessions work in my post pages, but not in pages such as archive etc. which leads me to suspect a problem with my template, but as I don’t know at what stage files such as wp-config are called, I can’t see where the problem is.

    Plesae help. This is driving me insane.


Viewing 5 replies - 1 through 5 (of 5 total)
  • PS – The weird thing is that this works perfectly on my local server. It’s only on the live version that sessions suddenly stop working, so it seems that there could be a server configuration issue, perhaps?

    I am now getting a session, but when I move between wordpress pages and pages in my static site, the session does not persist, and a new session is set up. When I go back to wordpress pages the previous session is still active on these pages! Any ideas?

    Well, just in case it’s useful to anybody I’ll let you know how I fixed it in the end:

    The whole problem was down to the canonical domain set in the wordpress settings. I set a canonical domain via .htaccess and set the same canonical domain in wordpress et voila!

    Now I can happily use sessions just by starting the session in the normal way at the top of my theme template pages.

    This was also causing a ‘same-domain policy’ issue when trying to use ajax, but the canonical domain fixed this too.

    Can’t believe it’s taken me this long to work this out! I’m officially retarded.

    Hi, can U send your htaccess file on my @?
    I have this same problem with session.


    Put this in your .htaccess to rewrite all urls to the www. version:

    <IfModule mod_rewrite.c>
       Options +FollowSymLinks
       Options +Indexes
       RewriteEngine On
       RewriteBase /
       RewriteCond %{HTTP_HOST} ^yourdomain\.com$
       RewriteRule ^(.*)$$1 [R=301,L]

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sessions not working – Tried everything!’ is closed to new replies.