Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Load custom session_id and edit

Hello! I try to figure out how to start session with custom session id.

Basicaly from admin panel I want to send a request to API with a session id hash, API need to load it (something like sessionid($sessionid); sessionstart() and if exists return informations from that session.

Is this possible ? Thanks!

Session ID is being sent to the client's browser in a Set-Cookie HTTP directive, now what exactly do you want to do with request to an external API which is not running a browser?



2.3k

What I asked has nothing to do with cookies.

This is what I want to do with phalcon API, but didn't find a way to do it with session service:

session_id($_GET['session_id']);
session_start();
die(json_encode($_SESSION));


42.8k
Accepted
answer

What I said has nothing to do with the Cookies itself, it's about how generated sessionID (what you asked for) acts as a glue between client's browser and your server. Now what you provided here with session in plain PHP does not make any sense to me, but here it is - Phalcon's version of that code logic of yours:

$di->setShared('session', function () {
    $request = $this->getRequest(); //we need Request service

    $session = new \Phalcon\Session\Adapter\Files(); //or any other supported adapter
    $session->setName('MySessionCookieName');
    $session->setId($request->getQuery('session_id', 'alphanum', $session->getId())); //filter and default value are optional, as I have no clue what you want to achieve with this
    $session->start();
    return $session;
});

$notSureWhy = json_encode($di->getShared('session')->get('youNeedToKnowKeyWhichHoldsYourSessionDataHere'));


2.3k

Perfect, thank you!