Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share sessions between php app and socketio app #13

Closed
saada opened this issue Apr 12, 2016 · 2 comments
Closed

Share sessions between php app and socketio app #13

saada opened this issue Apr 12, 2016 · 2 comments
Labels

Comments

@saada
Copy link

saada commented Apr 12, 2016

I'm using Yii2 and I'm trying to figure out how I could use this library with an existing app. Could you point to an example of a shared session/cookie system? A simple example would be to login via the main app and leverage the same cookie and session to skip authorization of a websocket session.

Great work btw. Thanks!

@walkor
Copy link
Owner

walkor commented Apr 12, 2016

Phpsocket.io not support session or cookie yet.
It will take some time to achieve these features and I'm not sure whether or not to achieve them.

At present, I think the simple way is sending authorization data through the client emitting.

@ghost
Copy link

ghost commented Jun 24, 2016

//-----------------------------------read session opera start----------------------------------------------
$cookies      = $socket->handshake['headers']['cookie']; // hare get client header is trouble,need to grep,otherwise dot‘t know has the array information。

// string to cookie array。phpsocketIO not found the functions。
$cookiesList  = explode(';', $cookies);
$cookieResult = [];
foreach ($cookiesList as $value) {
    list($k, $v) = explode('=', $value);
    $k = trim($k);
    $v = trim($v);
    $cookieResult[$k] = $v;
}

//here can use session_save_path function get the session path info,but redis or memcached need other method。
$sessionStr = file_get_contents("/tmp/sess_{$cookieResult['PHPSESSID']}");
$result     = session_decode($sessionStr);
var_dump($_SESSION);
echo "\n";
//-----------------------------------read session opera end----------------------------------------------





//-----------------------------------save session opera start----------------------------------------------
$_SESSION['bbb'] = 'ccc';
$sessionString   = session_encode(); 

file_put_contents("/tmp/sess_{$cookieResult['PHPSESSID']}", $sessionString, LOCK_EX);
//-----------------------------------save session opera end----------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants