How to get an anonymous user session id? I am writing a chat module where anonymous users are able to chat with a logged in user via an external websockets connection.

I need an ID to uniquely distinguish the anonymous users and assign them to different connections and keep track of the status of the connection.

How do I (securely) get a unique user id or session id for an anonymous user ?
You're looking for PHP's session_id():


  session_id() is used to get or set the session id for the current session.