I have a domain. Let’s call it www.example.com for this question. Thanks to the wonders of how I have things setup and/or WordPress, if I were to type in example.com it would redirect me to www.example.com and WordPress would do its thing. I also have a subdomain called members.example.com in which I have built a rather elaborate system using CodeIgniter into the folder /members off of public_html.
In a perfect world, what I would like to do is be able to put some php code into WordPress that would allow someone reading the “www” side of things to be able to determine if they are also currently logged in on the “members” side of things. I know the CodeIgniter session persists so that whenever I jump on to the members side, I’m still logged in. My first thought was to put together a quick page in CI that did this:
public function isLogged()
{
$x = "off";
if ($this->session->userdata('memberKey') != 0) {
$x = "on";
}
echo $x;
}
Then, whenever I would run the link members.example.com/login/isLogged , I would always get either “off” or “on” to determine if I was in or not. The memberKey would be either 0 for not logged in, or a number based on someone’s corresponding key in the database. My hope was that I would be able to run something like THIS from the www side (within WordPress)
$homepage = file_get_contents('http://members.example.com/login/isLogged');
…and I would be able to act on whether the person was logged in or not. Well, obviously the flaw here is that when I call the above function, I’m always going to get “off” as my result because I’m making that call from the server, and not from the client in question that needs this information.
What would be the most elegant solution to being able to read this information? Is there a way to read cookies cross platform?
Well, I realized that I worked through the process, and I don’t want to leave anyone hanging, so my solution was this:
First, I know that for my cookies, I went into codeIgniter’s /application/config/config.php and put the following in as my cookie domain (line 269 – and I’ve changed the domain name here to protect my client, obviously)
I’m being careful here, and using the “.” before the domain to cover all subdomains.
I also know that I’m writing my session data to a database. So, on the WordPress side of things, I put in this code at a certain location:
Then, I now have a way to determine if a member is logged on to the “members” side or not. Question is… are there any holes in what I’m doing that I should worry about?