www.webdeveloper.com
Results 1 to 5 of 5

Thread: Integrating CodeIgniter with Wordpress

  1. #1
    Join Date
    Feb 2007
    Posts
    63

    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:

    $this->ci->router->routes['default_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();

    $CI->session->set_userdata(array(
    '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?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,247
    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

    eBookworm.us

  3. #3
    Join Date
    Feb 2007
    Posts
    63
    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 :
    require_once '../wp-blog-header.php';

    add_filter('site_url', 'ci_site_url', 1);

    function ci_site_url()
    {
    include(APPPATH.'/config/config.php');
    return $config['base_url'];
    }


    fixes it.

  4. #4
    Join Date
    Feb 2007
    Posts
    63
    I'm now approaching 7 hours of looking at this and have googled it to death.

    FYI.

    I have tried:

    Adding session_start() to wp_config.php

    Turning off wp_unregister_GLOBALS

    Session is still being destroyed on each request.

  5. #5
    Join Date
    May 2013
    Posts
    1

    ContribSurvey Opensource

    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.
    http://www.developers.contrib.com/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.
    http://www.developers.contrib.com

    contribcom@gmail.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles