Index Forums Developer’s Forum Q2A & Drupal 6 integration

This topic contains 1 reply, has 2 voices, and was last updated by  MifX 3 years, 6 months ago.

  • Author
  • #1231


    Here is a code that I wrote(Or improved to use for drupal, can’t remember which) for Q2A’s Single Sign-On(SSO) with Drupal 6. I don’t remember how it worked, so if you used it and it had any problems let me know.
    Step 1
    in drupal open “\sites\default\setting.php” and add:

    $cookie_domain = '';

    Step 2

    now add this code to your “qa-config.php” file:

    	 // Database (for login/stats integration)
    	define('EXT_WEBADDRESS', '');
    	//define('DRUPAL_ROOT', dirname(getcwd() ).'\\');
    	define('DRUPAL_ROOT', '/drupal-directory/');
    	//$current_path = getcwd();
    	//define('DRUPAL_ROOT', dirname(getcwd() ).'\\');
    	require_once DRUPAL_ROOT . 'includes/';

    it should let you use authentication features in Drupal. don’t forget to set right value for DRUPAL_ROOT and EXT_WEBADDRESS.

    Step 3

    Now add this code to your “qa-external-users.php” file.

      if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
    		header('Location: ../');
    	function qa_get_mysql_user_column_type()
    		//users > uid > int(10)
    		return 'INT';
    	function qa_get_login_links($relative_url_prefix, $redirect_back_to_url)
    		return array(
    			'login' => EXT_WEBADDRESS.'user/',
    			'register' => EXT_WEBADDRESS.'user/register',
    			'logout' => EXT_WEBADDRESS.'user/logout'
    	function qa_get_logged_in_user()
    		global $user;
    		foreach($user -> roles as $key => $value)
    			if ($value=='administrator')
    		if ($user -> uid==0)
    			return null;
    		else {
    			if ($user_is_admin)
    			elseif (current_user_can('editor'))
    			elseif (current_user_can('contributor'))
    			return array(
    				'userid' => $user->uid,
    				'publicusername' => $user->name,
    				'email' => $user->mail,
    				'level' => $level,
    	function qa_get_user_email($userid)
    		$thisUser = user_load(array('uid' => $userid));
    		return $thisUser->mail;
    	function qa_get_userids_from_public($publicusernames)
    		if (count($publicusernames))
    			return qa_db_read_all_assoc(qa_db_query_sub(
    				'SELECT name, uid FROM users WHERE name IN ($)',
    			), 'name', 'uid');
    			return array();
    	function qa_get_public_from_userids($userids)
    		if (count($userids)) {
    				'SELECT uid, name, mail FROM users WHERE uid IN (#)',
    			), 'uid');
    			foreach ($userfields as $id => $fields) {
    			return $useridtopublic;
    		} else
    			return array();
    	function qa_get_logged_in_user_html($logged_in_user, $relative_url_prefix)
    		return '<A HREF="'.htmlspecialchars($relative_url_prefix.'user/'.urlencode($publicusername)).
    			'" CLASS="qa-user-link">'.htmlspecialchars($publicusername).'</A>';
    	function qa_get_users_html($userids, $should_include_link, $relative_url_prefix)
    		foreach ($userids as $userid) {
    			if ($should_include_link)
    				$usershtml[$userid]='<A HREF="'.htmlspecialchars($relative_url_prefix.'user/'.urlencode($publicusername)).
    					'" CLASS="qa-user-link">'.$usershtml[$userid].'</A>';
    		return $usershtml;
    	function qa_avatar_html_from_userid($userid, $size, $padding)
    		return null; // show no avatars by default
    	function qa_user_report_action($userid, $action)
    	Omit PHP closing tag to help avoid accidental output


  • #1296


    Hi Towhid,

    Thank you for posting the script for Q2A to Drupal SSO.

    I tried the steps as described above but got error messages on Q2A:

    Notice: Trying to get property of non-object in drupal/qa/qa-external/qa-external-users.php on line 27
    Warning: Invalid argument supplied for foreach() in drupal/qa/qa-external/qa-external-users.php on line 27
    Notice: Trying to get property of non-object in drupal/qa/qa-external/qa-external-users.php on line 30

    I am using Drupal 6.36 and Q2A 1.7. Is there a step I am missing or some setting I should setup on Drupal first (I followed the steps for Q2A SSO)? Any help or point in the right direction is greatly appreciated!

You must be logged in to reply to this topic.