WordPress.org

Ready to get started?Download WordPress

Forums

is_user_logged_in fails if WordPress address (URL) not equal Site address (URL) (8 posts)

  1. Nanowisdoms
    Member
    Posted 3 years ago #

    Ok, this is a little obscure and I'd appreciate any help.

    I'm creating a blog in which some material is private and people need to login to get to. At present the blog is hosted at:
    http://www.thehostingdomin.org/blogdirectory
    and on the General Settings page WordPress address (URL) == Site address (URL). Everything works fine. The blog works, what's public is visible, what's not is hidden until a user logins. Everything is as it should be.

    Now the blog will be accessed via:
    http://www.therealdomain.org

    Now to make it work I have:
    a) set up my hoster to point http://www.therealdomain.org to http://www.thehostingdomain.org/blogdirectory
    b) changed the Site address (URL) to "http://www.therealdomain.org
    c) updated the .htaccess file in http://www.thehostingdomain.org/blogdirectory according to what the permalinks says it should be.

    Everything works fine too. When you're browsing the blog, all links have http://www.therealdomain.org instead of http://www.thehostingdomain.org/blogdirectory so visitors don't know about http://www.thehostingdomain.org.

    The problem comes when you login to view the private content. I can login either at:
    http://www.thehostingdomain.org/blogdirectory/wp-login.php
    or
    http://www.therealdomain.org/wp-login.php

    Either way after logging when I start browsing (i.e. browsing http://www.therealdomain.org) wordprss doesn't seem to know I've logged in. I've tracked it down to the function is_user_logged_in -- it thinks I'm not logged in.

    The odd thing is that while I browse using http://www.therealdomain.org, all admin work is done via http://www.thehostingdomain.org/blogdirectory and the admin side knows I'm logged in and works fine.

    Any suggestions on how to deal with this would be greatly appreciated as this is a big problem for me.

    Thanks

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Undo all of your domain redirections and then review Giving_WordPress_Its_Own_Directory.

  3. Nanowisdoms
    Member
    Posted 3 years ago #

    Thank you for your response, however that doesn't address the issue. I have wordpress in its own directory running fine (i.e. wordpress address and site address are the same domain).

    My problem is that the is_user_logged_in doesn't work if the wordpress address domain and site address domain are different.

  4. Nanowisdoms
    Member
    Posted 3 years ago #

    I"m wondering if what MarkRH said

    The cookies are being set with a backtolifemeditations.com domain when logging in; however, the CD pages below are going to http://www.backtolifemeditations.com instead so the cookie does not match.

    here:
    http://wordpress.org/support/topic/is_user_logged_in-incompatible-with-firefox-and-chrome?replies=7#post-2068645

    is the same problem and if so how can make this work (i.e. adduress URL domain & site URL domain are different) so I can tell if someone is logged in and get their user info?

    Thanks for any help.

  5. Nanowisdoms
    Member
    Posted 2 years ago #

    Found the solution and it was easier than I thought. Since I have set up my hoster to point http://www.therealdomain.org to http://www.thehostingdomain.org/blogdirectory I thought that perhaps WordPress won't realize the blog is in a directory if set the "WordPress address (URL)" to http://www.therealdomain.org also (i.e. both General Settings page WordPress address (URL) and Site address (URL) are set to http://www.therealdomain.org).

    It worked like a charm -- just as if I was hosting on http://www.therealdomain.org and installed the blog in the root there. I had to go through some of the tables and fix up some URLs plugins had set as options, and a few URLs in some posts, but over all nothing much needed to be changed.

  6. emoedwin
    Member
    Posted 2 years ago #

    Hi, Nanowisdoms.

    I think I have the same situation like yours. I've followed the way you did. It works well at the first glance (at least, the login problem is solved).

    What my question is, what is the follow-up steps after the changing the both General Settings page WordPress address (URL) and Site address (URL)? could you tell me in detailed about it?

    thank you very much!

  7. Nanowisdoms
    Member
    Posted 2 years ago #

    The only other thing I had to do was manually fix up the .htaccess file. I had set my permalinks to /%post_id%/ but after changing the site and wordpress URL, I checked the permalink page and for some reason it said it could not update the .htaccess file due to security restrictions, but it gave the lines to put there. (If I change WordPress URL back, the .htaccess is updated fine, so must be something to do with access via the therealdomain.org.) So I cut and paste them via ftp into the .htaccess file located here:
    http://www.thehostingdomain.org/blogdirectory

    and removed the old lines in the file. Essentially the difference was the new lines didn't reference /blogdirectory any more. The whole blog looks and works like it's at:
    http://www.therealdomain.org/

    and not at:
    http://www.thehostingdomain.org/blogdirectory

    So far WordPress doesn't know otherwise. Even my robots.txt file, etc. are all in http://www.thehostingdomain.org/blogdirectory and they're all accessed as if they are in the root of http://www.therealdomain.org/.

  8. Nanowisdoms
    Member
    Posted 2 years ago #

    The other thing I did was go through the various tables using myPhpAdmin. Back up your database first. Then I accessed each table and searched for "blogdirectory". Where ever I found it I changed (usually):
    http://www.thehostingdomain.org/blogdirectory
    to
    http://www.therealdomain.org/

    Most of the changes were in tables created by plugins and wp_options. For example in wp_options, I'd browse the table, click on "Search" and whre it says:
    option_value longtext utf8_general_ci LIKE %...%

    I would enter "blogdirectory" without the quotes. That would give a list back and I would edit each item manually. Cut and paste into notepad, and search for "blogdirectory", make the change, paste back into myPhpAdmin and update.

    Also I had to update any URLs pointing to my own blog in my own posts. Those I found using:
    http://urbangiraffe.com/plugins/search-regex
    I made the changes manually, but used search-regex to find them.

    And then I had to fix any hard-coded menu/nagivation items I had.

    Basically look everywhere (plugin configurations, PHP code, CSS files for background image URLs, widgets, etc. etc.) for
    http://www.thehostingdomain.org/blogdirectory
    and change it to
    http://www.therealdomain.org/

    There were a few items in the options tables that just looked rathter strange and I didn't change (can't remember which now, but I think they are to do with recently edited stuff and gets revised on it's own.

Topic Closed

This topic has been closed to new replies.

About this Topic