Skip to:
Content
Pages
Categories
Search
Top
Bottom

.htaccess/Cookie woes!

  • @macwise

    Member

    I am currently having a problem where when I log in to wordpress (or bbpress) at url:myurl.com, then click a link that is directed to http://www.myurl.com, then I am no longer logged in. (Cookie issues). I am trying to figure out how to define either *.babyquestions101.com (preferably), or if that won’t work then babyquestions101.com AND http://www.babyquestions101.com.

    Give it a shot here:

    http://babyquestions101.com/

    and the forum is here:

    http://babyquestions101.com/forum/

    PLEASE CREATE ANY ACCOUNTS WITH THE WORD “TEST” AND ANOTHER WORD/NAME IN THE ACCOUNT NAME, unless of course you intend on keeping the account.

    UPDATE:

    My wordpress options blog url (in the wordpress admin panel) is listed WITH the “www” in front of the domain.. I am digging into mod_rewrite directives, but to be honest, I’m not really grasping it. Right when I think I have it figured out, it throws me. I have been able to get requests going to http://babyquestions101.com to redirect to http://www.babyquestions101.com/ using mod_rewrite in the .htaccess files. However, when I try it out in the forums, (http://babyquestions101.com/forum/) it just resolves at that address, and doesn’t insert the www. Any ideas?

Viewing 8 replies - 1 through 8 (of 8 total)
  • @ziyphr

    Member

    You should need to use .htaccess. Best thing is to override the way cookies are created. For WP these are in wp-settings.php around line 185. To have a shared cookie for the whole site I changed the cookie scope replacing:

    codeif ( !defined(‘COOKIEPATH’) )

    define(‘COOKIEPATH’, preg_replace(‘|https?://[^/]+|i’, ”, get_option(‘home’) . ‘/’ ) );code

    With:

    codeif ( !defined(‘COOKIEPATH’) )

    define(‘COOKIEPATH’, ‘/’ );code

    Setting the www bits etc can be done in a similar way. Assuming you’ve integrated your users, if you set the cookie path to ‘/’ with domain .babyquestions.101.com you should be fine.

    @macwise

    Member

    Ziyphr,

    Thank you so much for your reply. I think this is really the solution that I have been looking for. It just doesn’t make sense to me to only have one subdomain registered in the cookies, and I wasn’t sure how wordpress handled the adding of a subdomain.

    I am still moderately new to php, so I’m not sure I follow the last paragraph in terms of proper form and syntax, and so I’d prefer to ask that “stupid question” rather than sound smart and fail. ;). Can you let me know exactly what you think should go there, in terms of syntax? That would be greatly appreciated.

    P.S. It sounded like you meant to say “You should NOT need to use .htaccess? Just checking to be sure…

    Thanks so much for your help.

    @ziyphr

    Member

    You’re correct I missed a word out – htaccess isn’t be needed.

    I’ve not got much experience with bbPress but recently integrated WP and Vanilla. To confirm, are you intending to have 1 user table shared between your blog and forum? (so users can move seamlessly between the two)

    @macwise

    Member

    Yes, that’s how I have it set up now. It works quite well, and cookies are shared. The only real problem is the www vs the non www addresses.

    @macwise

    Member

    Ok, I got it figured out…I’ll post a more full breakdown tomorrow when my heads about me. Thanks for all your help, everyone.

    @ziyphr

    Member

    I had a look at the WP code but haven’t had a chance to look at bbPress’ yet. Would like to hear your solution. One thing I noticed was when you try entering www on here it filters them out.

    @macwise

    Member

    STATUS: RESOLVED

    Ziyphr,

    I’ll preface this by saying that I love Ahi Tuna dishes at restaurants. What is it about that huge hunk of raw fish meat that’s only seared to (probably) keep men’s wives from refusing to share a bed with a man who would eat a classic “dry heave” food. So, why do I like it? Well, it’s not the big chunk of meat that draws me in and pleases my palate. It’s the simple glaze that I often find on top; the light, sweet sauce that perfectly compliments the fish. As they say, “The secret’s in the sauce.”

    So, the “sauce” for this problem was the secret, and the sauce ended up being all too simple. Ziyphr first directed my friend and I to wp-settings.php. (He said to check out line 185, but mine was around 151-160). I found the code that called the siteurl and home, both of which would have returned http://babyquestions101.com, as that is what I have listed in my admin panel. I thought I needed to modify those to somehow spit out two domains, with the www and sans.

    My friend also informed me that he believed that cookie domains really need two dots, the first before the domain and the second after the domain but before the ‘com’. In my case it would be .babyquestions101.com. How to get ‘siteurl’ or ‘home’ to reflect that was a challenging thought.

    One side-note for anyone trying this same thing, DON'T CHANGE YOUR SITE ADDRESS OR HOME ADDRESS TO ANYTHING OTHER THAN \"WWW.MYURL.COM\" OR \"MYURL.COM\" IN THE ADMIN PANEL. Doing so will cause you more headaches than when you meet your mother in law for the first time. (Ok, that was an exaggeration, but only slightly).

    Once I got that mess sorted out, we tried to hard code in the .babyquestions101.com, replacing

    define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_settings('home') . '/' ) ); with

    define('COOKIEPATH', '.babyquestions101.com');

    This didn’t work, and all hope was lost. Curiosity getting the best of me, I opened up my preferences panel in Safari and pulled up the list of all my stored cookies to see if there were any similarities/discrepencies between my cookie and other sites’ cookies. This is where I saw my cookie had the value “www.babyquestions101.com” under the heading “website” where most other sites were listed as “.siteurl.com”, missing the www that seemed to be plaguing me. I decided that was what I needed changed, and when I looked back at the code in wp-settings.php, I discovered that line 160 was unique from the others.

    if ( !defined('COOKIE_DOMAIN') )
    define('COOKIE_DOMAIN', false);

    I decided to change this to this:

    if ( !defined('COOKIE_DOMAIN') )
    define('COOKIE_DOMAIN', '.babyquestions101.com');

    What do you know…I dumped my cookies for my site, refreshed the page, logged in, checked the cookie, and there it was, ‘.babyquestions101.com’. Now for the true test, I got rid of the ‘www’ in the address bar, hit return, and VOILA! I was still logged in. Everything was seamless. I was now the owner of a spiffy wordpress/bbpress integrated site that shared cookies across sites and subdomains. No crazy .htaccess directives, no checking and double checking every last link in my site to reflect my choice of domains.

    This is the way it should be done. I’m quite surprised it was such a simple solution, and that nobody seemed to be aware of how simple the solution is. I hope this is helpful to someone else trying to share cookies across multiple subdomains.

    @gostallion

    Member

    HELP!

    Ok I’ve been working on my site for an entire day and can’t seems to have things figured out.

    I’ve been trying to get bbpress and wp to integrate or share cookies with no luck at all. I’ve got wp in http://www.website.com/community and bb in http://www.website.com/community/bb

    I would run and install bb first and after I changed the password of my key master I would run wp but upon login I cannot logout!

    I’ve tried many reccomendations I found in the forum but none work. Anyone with any idea what went wrong?

    note: .htaccess is in /bb folder

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar