Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Q2A Core by

I am trying to implement a forum to my existing CodeIgniter site. My setup for Q2A is domain.com/q2a/

I would like to have a single sign on. I went through the external user doc, and also read every single question regarding SSO. Most of them were about wordpress.

I store the session in a table named ci_sessions.

users table does not store sessions.

So probably I am looking at using INNER JOIN or some other JOINS. My question is how do I modify this to achieve my goal?

$userid = $_COOKIE['cisession'];

            $result = qa_db_read_one_assoc(qa_db_query_sub(
                'SELECT email FROM users WHERE id=$',

When I print $userid it returns the last session that was stored inside ci_sessions table.

1 Answer

+1 vote
selected by
Best answer

The way you did it will log you in as a session. Meaning that when ever a session is created by CI your query will run that. And you will see it logged in, but you actually want to get the user not the session.

Here is how I've done it:

1-Copy the index.php into external-user folder

2- Change the System and Application path

    $system_path = '../system';
    $application_folder = '../application';

Assuming CI is your main site, and Q2A is in a folder.

3-  Inside qa-external-users.php add the following code inside qa_get_logged_in_user() .

    $CI =& get_instance();
    $CI->load->library('session'); //if it's not autoloaded in your CI setup

Remove session_start() as the session is already started.

Replace your query with this:

$userid = $CI->session->userdata('user_id');
 $result = qa_db_read_one_assoc(qa_db_query_sub(
                'SELECT * FROM users WHERE id=$',

Of course, I don't know the way your table is setup, but you might do some changes.

Hope it help

That worked great, thank you