1

I have two separate WP installs. The main site (a.com) and the blog for that site, which is on a subdomain (blog.a.com).

I need to be able to check if a user visiting blog.a.com is logged in to a.com. What is the best way to do it?

As most of the users (if not all) who are logged in to site a.com will be visiting blog.a.com by following a link from site a.com, I thought about passing a variable in the URL and then checking for that variable (or its value) on blog.a.com using $_GET. Something like this:

    <?php
    if( isset( $_GET['sitea-loggedin'] ) ){
      //display some links
    }

One of the downsides of doing it this way, is that if a user who is logged in to a.com visits the blog.a.com by going to the URL directly or not coming from the link with the parameter, he won't pass the $_GET check. This isn't much of a problem, but I wonder whether there is a better way of doing it, or are there any possible security risks of doing it this way?

While talking to a colleague of mine, he suggested checking the WP cookie ([wordpress_loggeed_in_xxx]), however, this cookie isn't available when you are on a different domain.

I want to do the logged in check just to display some links on blog.a.com that would take the user back to some pages on a.com.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.