dongling3243 2012-08-28 19:25
浏览 28
已采纳

需要使用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?

  • 写回答

1条回答 默认 最新

  • douxin8610 2012-08-28 20:28
    关注

    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?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决