Integrating CodeIgniter with Wordpress
This is causing me no end of grief, I thought I had cracked it but it seems I still have a problem.
wordpress is at root level /
codeigniter is off the root in /ci/
I thought it was ok, I could call wordpress functions from codeigniter like get_header(); etc
The first issue I had was I was unable to access the 'routes' attribute from a standard CI controller:
'ci' was NULL.
To resolve this issue I did; $this->ci = get_instance();
Which seemed to fix it. Whether this is the correct way of doing so or not I don't know.
I then have a login function, which commits some data to a session object. I do this in a Custom CI library class like so:
$CI =& get_instance();
'logged_in' => true,
'user_id' => $row['user_id'],
'username' => $row['username'],
'user_type_id' => $row['user_type_fk'],
'user_role' => json_encode($usr_role),
'theme' => $row['theme_url']
I have done a var_dump after this line on $CI->session->userdata and they have been set. Once logged in I redirect the user to another page, which uses a 'secure controller' (basically checks the user is logged in to access the page. This inherits from CodeIgniters standard 'CI_Controller'
However, when I do $this->session->userdata on this page, there is a session there, but it has a different session_id and none of my previous userdata. Each time I refresh this page a new session id is created. This is not the functionality I expect at all. I expect this to have the same session id which is maintained throughout, including my previously set userdata.
What am I doing wrong, and any suggestions?
If my memory is correct (which is never a sure bet), the out-of-the-box CI session functions are configured differently than "typical" PHP session use, including session IDs/data being essentially single-use (would explain why you get a new session ID on each request, I think?). If that conflicts with what you want/need to do, you may need to just use PHP's session_start() and $_SESSION array throughout, instead of depending upon the CI session class/methods, or see if CIs session class has configuration options that make it act more "normally"?).
Or you could wait for a real CI expert to give a better answer. (I've used it on a few projects, but nothing recently.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Ok this is very much related to Wordpress. If I remove the wordpress integration line from my CodeIgniter index.php this session issue is no longer present.
It's as if wordpress is killing my ci session on each request.
To clarify; removing this :
add_filter('site_url', 'ci_site_url', 1);
I'm now approaching 7 hours of looking at this and have googled it to death.
I have tried:
Adding session_start() to wp_config.php
Turning off wp_unregister_GLOBALS
Session is still being destroyed on each request.
Guidelines for marketing our opensource apps:
If what you’re searching for is codeigniter survey libraries or open source code igniter libraries
There are few or minimal survey libraries open for codeigniter but here is one that we found useful and opensource.
Guidelines for marketing our developer site:
If what you’re searching for is developers wanting to contribute.
This is a real interactive forum and we are happy to contribute. However we also have a profound platform for developers who would like to get their codes in the open, get it on a premium brand wagon and then make money through performance or equity options. You could hop on and contact us anytime.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)