I have a chat application using PHP web socket. and I have almost completed it.now when refresh the page the connection has broken from server and I have to reconnect to it.and my requirement is how to maintain the session for each user and .another problem is that when I try to connect to server from another tab of same browser then another connection is created with different port number. if I maintain session I can overcome from it please help me how to maintain session in PHP Web socket.
Asked
Active
Viewed 2,212 times
2
-
please don't suggest to use other than php websocket like nodejs,socketIO etc – madan Dec 28 '12 at 05:59
2 Answers
1
you can send session id every time you send a new message to websocket server and you can easily check session with session id. like this
session_id("your session_id");
session_start();
if(isset($_SESSION["email/username/id whatever"]) && ($_SESSION["password"])){
keep connected and process request
}
else{
disconnect
}

Ravinder Payal
- 2,884
- 31
- 40
-
1I had faced some issues regularly and php is not event base so i decided to use python web socket rather than php web socket and assign the session to the object of python web socket as an attribute.Thank you so much for your reply – madan May 31 '14 at 13:40
-
no mention its my duty to help you can connect with on www.funnenjoy.com/ravinder (its a nice social networking site ) – Ravinder Payal May 31 '14 at 15:13
-1
You just need to start a session in the php page. You can use
session_start();
and then just pass the necessary variable to $_SESSION[]
(it is the session array), then you can access them till you open the browser or you manually unset the session variable array or destroy the session.
To unset the session you can use
unset($_SESSION['variableName']);
or if you wish to destroy all session then you can use
session_destroy();

Pankit Kapadia
- 1,579
- 13
- 25

Tatha
- 127
- 1
- 14
-
-
You don't have write additional code for that. PHP itself will handle this. You can pass object through the session array by normal array accessing convention. – Tatha Dec 31 '12 at 04:06