简体   繁体   中英

How can I keep $_SESSION data I set from wordpress authentication in CodeIgniter site?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM