0

I'm creating a client for protocol running over TCP/IP sockets,the protocol is request/respond but unlike HTTP, any party can initiate the request and get back respond. The protocol is session oriented and passes state between requests in its header fields. So I would like to build upon PHP native sessions management to manage sessions and avoid having to re-invent the wheel. But PHP sessions were build with http protocol in mind and assumes client capabilities related to sessions handling. For example

 session_start();

The above line sends a session cookie to the browser or in case session.use_cookies='0' is set sends url parameter.

The question is now, is there way PHP can be forced to use session id given in the code at run time or retrieved from other storage locations to get current session data. something like this.

//start session in index.php
  session_start();

// somewhere in other pages
  set_active_session_id('47f6ac750'); // magical function
   $name = $_SESSION['name'] // works as normal

So, in other words, I want to use php sessions outside HTTP protocol.To be precise, on the CLI.

1 Answer 1

2

session_id() can be used to set the session ID. And it does it before the session is started, which will save you a ton of headaches.

I just hope you're only doing this for educational purposes, because it sounds horrible.

Sign up to request clarification or add additional context in comments.

2 Comments

So session_id() sets the session id that will be used to get values in $_SESSION.
Yes, it is exactly what you asked for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.