ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
913 stars 375 forks source link

How can i use this class with sessions #80

Closed nizarnizario closed 8 years ago

nizarnizario commented 8 years ago

Hello, is there a way to use this class with $_SESSION ? i tried , but i could find how,,,

can you help me ?

ghedipunk commented 8 years ago

PHP needs to be started by a web server in order to use the $_SESSION variable. The Websocket server is started by the command line, not a web server.

However, the session cookies are available during the handshake. You can use that value, along with session_name() and session_start() to populate the $_SESSION variable. Just be sure that you write and close the session as soon as you're done, otherwise it'll be locked and could cause some difficult to troubleshoot issues.