WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sessions not working - Tried everything! (6 posts)

  1. animalmutch
    Member
    Posted 3 years ago #

    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.

    Thanks

  2. animalmutch
    Member
    Posted 3 years ago #

    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?

  3. animalmutch
    Member
    Posted 3 years ago #

    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?

  4. animalmutch
    Member
    Posted 3 years ago #

    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.

  5. chomiczek
    Member
    Posted 3 years ago #

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

  6. animalmutch
    Member
    Posted 3 years ago #

    Hi,

    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 ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
    </IfModule>

Topic Closed

This topic has been closed to new replies.

About this Topic