Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Login system outside Q&A directory

+2 votes
2,109 views
asked Feb 9, 2011 in Q2A Core by William Orellana
I know is part of the advance section, but can anyone help me or give me an idea how can I add the Q&A login system to my other directorys. I have already search the function or piece of code but I can't find anything.
commented Mar 16, 2011 by Mélanie
I understand what you want to achieve.. I guess it is feasible, but would required some work... As a hint, look at qa-app-users.php, this is the one the either use the external or internal information.
 I think this would worth being a whole new question!

1 Answer

+5 votes
answered Feb 10, 2011 by gidgreen
 
Best answer

Interesting question. Here's how you do it in your PHP code:

define('QA_BASE_DIR', '/PATH/TO/Q2A/');
 
require_once QA_BASE_DIR.'qa-include/qa-base.php';
require_once QA_BASE_DIR.'qa-include/qa-app-users.php';
require_once QA_BASE_DIR.'qa-include/qa-db.php';
 
qa_base_db_connect(null);
 
echo qa_get_logged_in_userid().' '.qa_get_logged_in_handle().' '.qa_get_logged_in_email().' '.qa_get_logged_in_level();
 
Replace /PATH/TO/Q2A/ above with the full path to your Q2A directory (the directory that includes qa-config.php). The last line shows the kind of information you can extract about the logged in user. If no user is logged in, all of these functions (defined in qa-app-users.php) return null.
commented Feb 10, 2011 by William Orellana
Thank you!!

Works great, and thank you for this great product.
commented Feb 6, 2012 by William Orellana
edited Feb 6, 2012 by William Orellana
Thanks again for the code.

The code worked great with 1.4, but stop working with the 1.5 beta and today I upgrade to 1.5 and still doesn't work. Any ideas??

UPDATE:

Looks like the "qa_base_db_connect(null);" function was delete from 1.5 what use now?
commented Feb 7, 2012 by gidgreen
You don't need to replace qa_base_db_connect(...) with anything and can just leave it out.
...