Reading Session Variables From PHP Socket Server Handshake

So say that i have a PHP socket server.

When a client connects a handshake occurs and the client sends their PHP session ID to the socket server.

The question is how i do read the variables related to the session ID in the socket server?

I’ve tried setting the current session id to that which i receive but it throws an error saying the headers were already sent or something.

IMPORTANT NOTE:

The socket server i’m running is only written with the standard functions provided in PHP. No libraries are involved.

help?

TLDR: Use something like Redis, Memcache or another database for your session store.

Due to the way PHP was originally designed/used, it expects to know the session id when the PHP process is starting. This makes sense in a web server context where a new PHP process would be started for every request. The tooling required to use the built in session handling simply doesn’t exist for PHP from the command line.

Technically I’m not saying it can’t be done, but you don’t want to. You’d have to restart PHP anytime you wanted to change the session id…

No u, just made a workaround

Care to share your solution? Might help someone else down the road.

first off all here: https://github.com/FullNitrous/Voidzehn
this is the full source of the website, the socket servers are in the socketserver1 and 2 folders.

anyway, a short explaination of it is basically that when the unknown user connects to the socketserver it is assigned a uid and stored in a list for further communication (normal stuff). The javascript client code though, reads the PHPSESSID from the browser and sends it over to the socketserver and the server recognizes it. Then when it has the ID the server can send a request to a file hosted on the apache server. it can then put in the query string what value it wants and give the ID for the user that the value is going to be read from. since this php file is on the apache server it can set the ID go the session variable array read the property and echo it back to the socketserver. In this manner the server has successfully read a session value. my intent was to read the username for a spesific PHPSESSID. and it works very nice. only thing is that this is unsafe and therefore this file that returns the values should be restricted to only be access from inside the server.