{"action":"opened","issue":{"url":"https://api.github.com/repos/kselax/esr-php-session/issues/1","repository_url":"https://api.github.com/repos/kselax/esr-php-session","labels_url":"https://api.github.com/repos/kselax/esr-php-session/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/kselax/esr-php-session/issues/1/comments","events_url":"https://api.github.com/repos/kselax/esr-php-session/issues/1/events","html_url":"https://github.com/kselax/esr-php-session/issues/1","id":381967150,"node_id":"MDU6SXNzdWUzODE5NjcxNTA=","number":1,"title":"share session between php and socket.io","user":{"login":"Invi7","id":45145884,"node_id":"MDQ6VXNlcjQ1MTQ1ODg0","avatar_url":"https://avatars1.githubusercontent.com/u/45145884?v=4","gravatar_id":"","url":"https://api.github.com/users/Invi7","html_url":"https://github.com/Invi7","followers_url":"https://api.github.com/users/Invi7/followers","following_url":"https://api.github.com/users/Invi7/following{/other_user}","gists_url":"https://api.github.com/users/Invi7/gists{/gist_id}","starred_url":"https://api.github.com/users/Invi7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Invi7/subscriptions","organizations_url":"https://api.github.com/users/Invi7/orgs","repos_url":"https://api.github.com/users/Invi7/repos","events_url":"https://api.github.com/users/Invi7/events{/privacy}","received_events_url":"https://api.github.com/users/Invi7/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-18T14:49:12Z","updated_at":"2018-11-18T14:49:12Z","closed_at":null,"author_association":"NONE","body":"Hello I hope you can help me,\r\nI want to create a Website, where the user can login with a simple php login. I store my sessions in a redis database.\r\nSo wenn the user is logged in I want, that socket.io sends a request to the node server that a new user with the Session id has logged in. unfortnatly i am not able to do this. maybe you can help me.\r\n\r\nhere is the code\r\n\r\n**PHP Script**\r\n`<?php\r\nrequire_once 'Esr_php_session.php';\r\n\r\n$obj = new Esr_php_session(array(\r\n  'esr_php_session_name' => 'my_session',\r\n  'secret' => 'my new secret',\r\n  'maxAge' => (60 * 60 * 24), // by default 24 hours\r\n  'EX' => 60,\r\n));\r\n\r\n// count views\r\nif (is_numeric($_COOKIE['esr_php_session']['views'])) {\r\n    $_COOKIE['esr_php_session']['views']++;\r\n} else {\r\n    $_COOKIE['esr_php_session']['views'] = 0;\r\n}\r\necho 'Views = ' . $_COOKIE['esr_php_session']['views'] . \"\\n\";\r\n\r\n// save and set up cookies\r\n$obj->save(); // save session to database\r\n\r\n\r\nvar_dump($_COOKIE['esr_php_session']);\r\n?>\r\n\r\n\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n  <meta charset=\"UTF-8\">\r\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n  <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\r\n  <title>Document</title>\r\n</head>\r\n<body>\r\n  <div class=\"message\">\r\n  Views = <span id=\"views\"></span>\r\n  </div>\r\n  <button id=\"plus\">plus</button>&nbsp;\r\n  <button id=\"zero\">zero</button>\r\n\r\n  <script src=\"../public/socket.io.js\" charset=\"utf-8\"></script>\r\n  <script src=\"../public/jquery.js\" charset=\"utf-8\"></script>\r\n  \r\n  <script>\r\n    var io = io('http://localhost:3000');\r\n    $('#plus').click(function(event) {\r\n      io.emit('plus', 'plus');\r\n    });\r\n    $('#zero').click(function(event) {\r\n      io.emit('zero', 'zero');\r\n    });\r\n    io.on('message', function(msg){\r\n      console.log(msg)\r\n      $('#views').text(msg);\r\n    })\r\n  </script>\r\n</body>\r\n</html>`\r\n\r\n\r\n\r\n**node socket server**\r\n\r\n`const express = require('express');\r\nvar esr_php_session = require('../index.js');\r\nvar io = require('socket.io');\r\nhttp = require('http');\r\nvar app = express();\r\nhttp = http.Server(app);\r\nio = io(http);\r\nhttp.listen(3000);\r\n\r\n// app.listen(3000);\r\n\r\nio.use(esr_php_session.socket_io_session({\r\n  esr_php_session_name: 'my_session',\r\n  secret: 'my new secret',\r\n  maxAge: (60 * 60 * 24), // by default 24 hours\r\n  ex: 60,\r\n}));\r\n\r\nio.on('connection', function(socket){\r\n  \r\n  console.log(socket);\r\n  \r\n  console.log('connected socket.id = ' + socket.id);\r\n\r\n  if(socket.esr_php_session){\r\n    if(socket.esr_php_session.views){\r\n      socket.emit('message', socket.esr_php_session.views);\r\n    }else{\r\n      socket.esr_php_session.views = 0;\r\n      socket.emit('message', socket.esr_php_session.views);\r\n    }\r\n  }\r\n\r\n  socket.on('plus', function(msg){\r\n    socket.esr_php_session.views++;\r\n    socket.esr_php_session.save();\r\n    socket.emit('message', socket.esr_php_session.views);\r\n  });\r\n\r\n  socket.on('zero', function(msg){\r\n    socket.esr_php_session.views = 0;\r\n    socket.esr_php_session.save();\r\n    socket.emit('message', socket.esr_php_session.views);\r\n  })\r\n\r\n})`\r\n\r\n"}}
{"actor":{"display_login":"Invi7"}}