需要使用wordpress将子域codeIgniter信息传递给域
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?
我有一个域名。 我们称之为 www.example.com em>来解决这个问题。 感谢我如何设置和/或Wordpress的奇迹,如果我输入 example.com em>,它会将我重定向到 www.example.com em>和Wordpress 会做的事情。 我还有一个名为 members.example.com em>的子域名,我在其中使用CodeIgniter构建了一个相当精细的系统到public_html文件夹 / members strong>。 p> \ n
在一个完美的世界中,我想做的是能够将一些PHP代码放入Wordpress中,这样可以让读取“www”方面的人能够确定它们是否也是当前记录的 在事物的“成员”方面。 我知道CodeIgniter会话仍然存在,因此每当我跳到成员端时,我仍然会登录。我的第一个想法是在CI中组合一个快速页面来执行此操作: p>
然后,每当我运行链接 members.example.com/ login / isLogged strong>,我总是得到“关闭”或“打开”以确定我是否在。 如果未登录,memberKey将为0,或者基于某人在数据库中的相应密钥的数字 em>。 我希望能从www端(在Wordpress中)运行类似THIS的东西 p>
...我将能够根据该人是否登录而采取行动。 好吧,显然这里的缺点是,当我调用上面的函数时,我总是会“关闭”作为我的结果,因为我正在从服务器进行调用,而不是来自需要此信息的客户端 。 p>
能够阅读此信息的最佳解决方案是什么? 有没有办法从跨平台读取cookie? p>
div>
公共函数isLogged()
{
$ x =“off”;
if($ this-> session-> userdata('memberKey')!= 0){
$ x = “on”;
}; n echo $ x;
}
code> pre>
nn $ homepage = file_get_contents('http://members.example.com /login/isLogged');
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?