Wordpress in CodeIgniter

I followed this guide: http://philpalmieri.com/2009/06/codeigniter-and-wordpress-play-well-together/

Which basically says: to install WordPress, make it work, then replace the index.php file with Code Igniters, and then at the bottom of the file right before we start CodeIgniter, you need a wp-load word press file.

Works great.

However, now my $ _SESSION is not working. I installed a code igniter to use database sessions and register session values, but it still doesn't work. I cannot log into my CodeIgniter system admin panel, I cannot do anything that requires sessions, because the sessions are not working. Lol

How to fix it?

+5
source share
2 answers

I did the following to make it work (I have the Code Igniter application in a separate directory in the Wordpress directory) - what I obviously do not like about this is that I had to change the main file in Wordpress,

First, I added the 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' ); 

Secondly, I realized that the Wordpress add_magic_quotes function distorts the global $ _COOKIE. This caused CodeIgniter to re-create a cookie every time the page loads or redirect, thereby breaking any continuity. So, I commented on this line in wp-includes.load.php (near line 545)

 //$_COOKIE = add_magic_quotes( $_COOKIE ); 

Then, to keep this feature in tactics for all other Wordpress-related cookies, I created the array_walk function to iterate over the global variable $ _COOKIE and apply add_magic_quotes to all cookies except my one in the wp-includes / load.php function

 /** * Applies Magic Quotes to the $_COOKIE global but ignores Codeigniter 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'); 

After that, I no longer had several cookies stored in my ci_sessions table, and the sessions were successfully saved.

Hope this helps!

+4
source

It explains here how WordPress disables session variables and a possible solution. Unfortunately, it seems that you need to modify the kernel files - in wp_unregister_GLOBALS , which, it seems, will not have any hooks that could help.

+1
source

Source: https://habr.com/ru/post/950163/


All Articles