How do I get the userid?

I'm an absolute beginner with elgg & php...so apologies for the lame question!

1'm trying to integrate cometchat with elgg and I need to get the user id of the current logged in user. I tried these without success:

        $userid = $_SESSION['userid']->userid;

and

        $userid = getuserid();

 

Any pointers greatfully received.