CodeIgniter中的Wordpress [英] Wordpress in CodeIgniter

查看:56
本文介绍了CodeIgniter中的Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已遵循此指南: http:// philpalmieri.com/2009/06/codeigniter-and-wordpress-play-well-together/

基本上说要安装wordpress,使其正常工作,然后用Code Igniters替换index.php文件,然后在我们启动CodeIgniter之前在文件底部,要求word按下wp-load文件。

Which basically says, to install wordpress, get it working, then replace the index.php file with Code Igniters, and then at the bottom of the file right before we initiate CodeIgniter, require the wp-load file of word press.

工作正常。

但是,我的$ _SESSION无法正常工作。我已将代码点火器设置为使用数据库会话,并记录了会话值,但仍然无法正常工作。我无法登录我的CodeIgniter系统管理面板,因为会话无效,所以我无法做任何需要会话的事情。大声笑。

However now, my $_SESSION doesn't work. I have set code igniter to use Database sessions, and its logging the session values, but It still doesn't work. I can't log into my CodeIgniter systems admin panel, I can't do much of anything that requires sessions because Sessions dont work. LOL.

如何解决此问题?

推荐答案

我做了以下是使其工作的方法(我在Wordpress目录中的单独目录中有一个Code Igniter应用程序)-很显然,我喜欢的是,我必须在其中修改一个核心文件WordPress的。

I did the following to get this to work (I have a Code Igniter application in a separate directory within a Wordpress directory) -- what I obviously don't like about it is that I had to modify a core file within Wordpress.

首先,我在wp-includes / load.php的$ no_unset数组中添加了代码点火器cookie名称,在我的情况下是ci_session:

First, I added my Code Igniter cookie name to the $no_unset array in wp-includes/load.php In my case it was ci_session:

    $no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix','ci_session' );

第二,我发现Wordpress的add_magic_quotes函数正在破坏$ _COOKIE全局变量。这导致CodeIgniter在每次页面加载或重定向时重新创建cookie,从而破坏了任何连续性。因此,我在wp-includes.load.php中注释了这一行(第545行左右)

Second, I figured out that Wordpress's add_magic_quotes function was mangling the $_COOKIE global. This was causing CodeIgniter to re-create the cookie on each page load or redirect and thereby breaking any continuity. So, I commented this line out in wp-includes.load.php (around line 545)

//$_COOKIE = add_magic_quotes( $_COOKIE );

接下来,为使所有其他与Wordpress相关的cookie保持完整,我创建了一个array_walk函数来循环遍历$ _COOKIE全局,并将add_magic_quotes应用于所有cookie,除了wp-includes / load.php函数中属于我的cookie

Next, to keep this function in tact for all other Wordpress related cookies, I created an array_walk function to loop over the $_COOKIE global and apply add_magic_quotes to all cookies except for mine within the wp-includes/load.php function

/**
* Applies Magic Quotes to the $_COOKIE global but ignores Codeigniter's Cookie
* @param  string $value Value passed by array_walk function
* @param  string $key   Key passed by array_walk function
*/
function ci_ignore_magic_quotes($value,$key)
{
    if($key != "ci_session")
    {
        stripslashes_deep($value);
    }
}

//Put this line in place of the commented out line above...
array_walk($_COOKIE, 'ci_ignore_magic_quotes');

执行完此操作后,我的ci_sessions表中不再存储多个cookie,并且会话成功完成保留。

After I did this, I was no longer having multiple cookies stored in my ci_sessions table and sessions were successfully retained.

我希望这会有所帮助!

I hope this helps!

这篇关于CodeIgniter中的Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆