CometChat integration I need to implement Comet Chat, a facebook-chat-like third-party script, into my Craft project. 

Comet Chat can connect to most CMS and PHP framework but there is no Craft integration yet, so I tried to use the "custom coded site" procedure.

http://www.cometchat.com/documentation/installing-cometchat/custom-coded-site/php-site/

Comet Chat need to access a session variable to authenticate user. Ex: $_SESSION['userid'].

The problem: Craft write its session variables with some nice sorcelery that makes outside script unable to read it.

So, the Comet Chat is not able to read the userid, even if I made a Craft plugin who writes UserID in $_SESSION['userid'].

I also tried, by the Craft cookie ($_COOKIE values are bidirectionally accessible unlike $_SESSION values, of course) to find some relation or mechanism to tells Comet Chat who's the current user in Craft, unsuccessfuly.

Perhaps some other PHP scripts or cases may need to read the Craft session, so I'm pretty sure this question can be relevant for more than Comet Chat integration.

Any ideas?

Thanks in advance!
The Matt's answer was pretty complete and worked almost, but for the benefit of others, there is the changes required files to make it works:

in integration.php

find

define('SET_SESSION_NAME','');


change for

define('SET_SESSION_NAME','CraftSessionId');


and make your getUserID functions look like

function getUserID() {
            $userId = 0; // Return 0 if user is not logged in

            if ( $_SESSION[ 'craftUserId' ] ) 
            {
                $userId = $_SESSION[ 'craftUserId' ]; // Set this session variable in a Craft plugin
            }

            return intval( $userId );
    }


and in a Craft plugin, add this to a init() function

public function init()
    {            
        craft()-&gt;on('userSession.onLogin', function(Event $event) {
            $currentUser = craft()-&gt;userSession-&gt;getUser();
            craft()-&gt;httpSession-&gt;add( 'craftUserId', $currentUser ? $currentUser-&gt;id : null );            
        });
   }


If you want to be full-padded, you can also add something to unset your CraftUserId variable onLogout event, but I don't think it's needed.

Thanks a lot to Matt and Brad who helped me out on Easter day!