0

I have a CodeIgniter site that is nested in a Wordpress site.

If users already login to the Wordpress site (use $_SESSION variable to manage login) then they can access to CodeIgniter site too. But when I try to access $_SESSION in CodeIgniter site to check login, all the $_SESSION data I set in WordPress site is gone. I can only see the __ci_last_regenerate of CodeIgniter. I think that CodeIgniter clears all the data in $_SESSION.

How can I keep $_SESSION data I set from WordPress authentication (just use $_SESSION to handle ) in the CodeIgniter site?

1 Answers1

0

You have to integrate WordPress and CI together. To do this you have to write following line of code in index.php file of CI

require_once 'path/to/WordPress/Directory/wp-blog-header.php';

Also, understand that both the framework has their own SESSION management so you supposed to study and understand the structure of SESSION management in WP and CI.

Once you integrate WP and CI correctly I guess you can access all WP functionality into CI. So instead of directly accessing SESSION you can use WP functionality to check if user logged in or not using following function.

is_user_logged_in()

Read here for further details on integration

Vantiya
  • 612
  • 1
  • 4
  • 11
  • My client does not use Wordpress functionality for the authentication, they just use $_SESSION directly. My problem is that I have to access the data in $_SESSION array which is set in Wordpress site (my site is nested inside a Wordpress site) to be able to check if the user logged to not. – Võ Cao Sơn Oct 09 '19 at 08:04
  • Did you integrated WP & CI? – Vantiya Oct 09 '19 at 08:11
  • I didn't. I just tried to load the file I need through include_once. It's not about Wordpress, just the $_SESSION is cleared when I reload my CI page. – Võ Cao Sơn Oct 09 '19 at 08:15