PHPWebSocket-Chat icon indicating copy to clipboard operation
PHPWebSocket-Chat copied to clipboard

How can we send the logged in user id

Open manojdhiman opened this issue 10 years ago • 10 comments

hi , first of all thanx for this code. i am using this library to implement a chat application , problem is how can i send the logged in user id when a user connects to socket with function

Server.bind('open', function(data) { var user='user->name); ?>'; alert(data); });

manojdhiman avatar Feb 20 '15 13:02 manojdhiman

I aso wants to perform this task. any idea?

jignesh87 avatar Feb 26 '15 13:02 jignesh87

i implemented this task but not sure it is secure or not .. :p

if you want to check then server side file is https://github.com/manojdhiman/yii-login-register-with-chat/tree/master/chat_server

and client side https://github.com/manojdhiman/yii-login-register-with-chat/blob/master/themes/basic/views/layouts/main.php

please check this is just a try if you can improve this

manojdhiman avatar Feb 26 '15 13:02 manojdhiman

hiii..manoj I have created function in Server.php function getServerData(){

$sql = "SELECT id, user_name FROM user_master";

$result = mysqli_num_rows($conn, $sql);

if ($result->num_rows(result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        $d = "id: " . $row["id"]. " - UName: " . $row["user_name"]. "<br>";die;
    }
}else{
    $d = "0 results";
}
return $d;

} which is called when client == 1 if ( sizeof($Server->wsClients) == 1 ){ echo getServerData(); $Server->wsSend($clientID, "It's server!!"); } when i refresh connection becomes diconnect, and it returns nothing. Is there any prob?.

I wants to send data instead of message. Thanks . Jignesh

jignesh87 avatar Feb 28 '15 10:02 jignesh87

it should reconnect if you refresh the page .check your terminal after refresh the page with print something on close event like

function wsOnClose($clientID, $status) { global $Server; $ip = long2ip( $Server->wsClients[$clientID][6] );

$Server->log( "$ip ($clientID) has disconnected." );

}

manojdhiman avatar Mar 02 '15 04:03 manojdhiman

Hii,Manoj I have done server response sucessfully. One issue is when i try sending data from server as a video file it crashes my cmd, and it's not responding. Is it any way to send video from server side to the client? Thank you, Jignesh.

jignesh87 avatar Mar 11 '15 09:03 jignesh87

Hi, I use websocket, but i wanna send msg to 1 person, not to all,

can u help me ?

hamidteimouri avatar Feb 06 '17 10:02 hamidteimouri

Hi, I use websocket, but i wanna send msg to 1 person, not to all, can u help me ?

And not only that, i'm trying to hide the message if anyone connect to that websocket, only show the message to the person i want

juanjosv avatar Oct 22 '18 16:10 juanjosv

Hi, I use websocket, but i wanna send msg to 1 person, not to all, can u help me ?

And not only that, i'm trying to hide the message if anyone connect to that websocket, only show the message to the person i want

This was for 2 years ago. I fixed it !

hamidteimouri avatar Oct 22 '18 16:10 hamidteimouri

Hi, I use websocket, but i wanna send msg to 1 person, not to all, can u help me ?

And not only that, i'm trying to hide the message if anyone connect to that websocket, only show the message to the person i want

This was for 2 years ago. I fixed it !

Oh, sorry, i found this project and using it to develop a chat system , and i'm stuck in the same case.

juanjosv avatar Oct 22 '18 16:10 juanjosv

Hi, I use websocket, but i wanna send msg to 1 person, not to all, can u help me ?

And not only that, i'm trying to hide the message if anyone connect to that websocket, only show the message to the person i want

This was for 2 years ago. I fixed it !

Oh, sorry, i found this project and using it to develop a chat system , and i'm stuck in the same case.

You should use node js for that. PHP socket is not good for socket programming.

hamidteimouri avatar Oct 22 '18 17:10 hamidteimouri