简体   繁体   English

需要通过Wordpress将子域代码点火器信息传递给域

[英]Need to pass subdomain codeIgniter info to domain with wordpress

I have a domain. 我有一个域。 Let's call it www.example.com for this question. 我们将此问题称为www.example.com 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. 多亏了我如何设置和/或设置Wordpress的奇迹,如果我输入example.com ,它将把我重定向到www.example.com,而Wordpress将完成它的工作。 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. 我还拥有一个名为members.example.com的子域,在该子域中,我使用CodeIgniter将一个复杂的系统构建到public_html的/ members文件夹中。

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. 在一个理想的世界中,我想做的是能够将一些PHP代码放入Wordpress中,从而允许某人阅读事物的“ www”面能够确定他们当前是否也已登录“成员”事物的一面。 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: 我知道CodeIgniter会话会持续存在,以便每当我跳到成员端时,我仍会登录。我的第一个想法是在CI中放一个快速页面来完成此任务:

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. 然后,每当我运行链接members.example.com/login/isLogged时 ,我总是会“ off”或“ on”来确定我是否在里面。 The memberKey would be either 0 for not logged in, or a number based on someone's corresponding key in the database . memberKey将为0(表示未登录),或者为基于某人在数据库中对应密钥的数字 My hope was that I would be able to run something like THIS from the www side (within Wordpress) 我希望我能够在www端(在Wordpress中)运行类似THIS的东西

$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. 好吧,显然这里的缺点是,当我调用上面的函数时,我总是会得到“ off”作为结果,因为我是从服务器而不是从需要此信息的客户端进行该调用。

What would be the most elegant solution to being able to read this information? 能够读取此信息的最优雅的解决方案是什么? Is there a way to read cookies cross platform? 有没有办法跨平台读取Cookie?

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) 首先,我知道对于我的Cookie,我进入了codeIgniter的/application/config/config.php并将以下内容作为我的Cookie域(第269行-并且我已经更改了此处的域名以保护我的客户端)

$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: 因此,在Wordpress方面,我将这段代码放在某个位置:

$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? 问题是... 我应该担心的事情有什么漏洞吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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