简体   繁体   中英

Need to pass subdomain codeIgniter info to domain with wordpress

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)

$config['cookie_domain']    = ".example.com";

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:

$memCCinfo = unserialize(stripslashes($_COOKIE['ci_session'])); // Changed for OBVIOUS reasons
$mysqli = mysql_connect('localhost', 'NAME', 'PASSWORD'); // Changed for OBVIOUS reasons
$mysqlDatabase = mysql_select_db('DATABASE',$mysqli); // Changed for OBVIOUS reasons
$isLoggedCC = "off";
$sessInfoQry = mysql_query('SELECT user_data FROM ci_sessions WHERE session_id = "' . $memCCinfo['session_id'] .'"',$mysqli);
while ($sessInfo = mysql_fetch_assoc($sessInfoQry)) { 
    $breakOutInfo = unserialize(stripslashes($sessInfo['user_data']));      
    if (is_array($breakOutInfo)) { $isLoggedCC = "on"; }
}

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM