Hello There I`m working on drupal module make integration between cometchat 1.6.0 and Drupal 6.X
Comet chat want to know what is the user id is logged in so give me a function I must fix it suitable to my environment

function getUserID() {
	$userid = 0;
	
	if (!empty($_SESSION['userid'])) {
		$userid = $_SESSION['userid'];
	}

	return $userid;
}

I tried to do this

global $user;
	if ($user->uid !== 0){
		$userid = $user->uid;
	}

but dose`t work because comet chat and drupal separated environments and $user undefined in comet chat so T tried to use session
I dump $_SESSION but it`s empty .
my question is how can I save uid in $_SESSION to use it in comet chat

Thanks

Comments

gilcpd’s picture

I took this from the integration tutorial on CometChat:

http://www.cometchat.com/support/topic/7-integration-with-drupal-v6/page...

$GLOBALS['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; // or whatever your drupal root is

// get the base drupal directory and change to chdir to it
$base = str_repeat('../',substr_count($_SERVER['PHP_SELF'],'/')-1);
chdir($base);

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$userid = 0;
        
global $user;
$_SESSION['userid'] = $user->uid;

if (!empty($_SESSION['userid'])) {
  $userid = $_SESSION['userid'];
}

return $userid;
ayalsule’s picture

Thank u I solved using COOKIES

...

jubrette’s picture

Hello,
I have the same problem !!

How did you do please with COOKIE ?

Michsk’s picture

this is written by me: http://www.cometchat.com/support/topic/7-integration-with-drupal-v6/page... that's a step by step tuto. I stoped using cometchat so i don;t know if there's anything changed. But at the time that worked perfectly.

bonobo’s picture

The CometChat sales team uses spam tactics to market their product.

Because CometChat spams people, I do not recommend using CometChat.

See here for one such example.

jaypan’s picture

All advertising in spam.

Contact me to contract me for D7 -> D10/11 migrations.

fenda’s picture

Anybody get a good integration.php working for Drupal 7? They don't even have one.

A good programmer is a lazy programmer.

seb_x’s picture

Hi there, I managed to adapt integration.php file that is needed for integrating Drupal 7 with Cometchat.

Inside of the file I have erased my licence info. Changes as compared to the initial version:
- user name points to correct link on the site (/user/$uid)
- avatars are correctly displayed (mapped them to one my site image styles; update line 93 to match your setup)
- in case no avatar is available chatbox grabs nophoto.jpg (update line 94 to match your setup).
- both http/https protocols are suported (previously it worked only in http mode).

Feel free to correct my syntax since I'm not a PHP programmer ;-)

You can download it from this site (integration.txt): http://www.speedyshare.com/vJSWB/integration.txt

seb_x’s picture

vastra’s picture

Super thanks for re-uploading this by my request!

I've changed over to arrowchat in the meantime, but the integration is VERY similar so this will help me tons anyway :)

Thank you very much.
~Vas

wikibi’s picture

Can you please re-post. Would love to have for our drupal 7 upgrade. Thank you so much.

wikibi’s picture

Just spent a better part of an evening trying to figure this out. Can you please re-post the integration text file that is needed for drupal 7? Would be eternally grateful.