workerman icon indicating copy to clipboard operation
workerman copied to clipboard

Pass user_id to the server when connecting.

Open ExchangeAssets opened this issue 9 months ago • 2 comments

Is there a way on the client side to transfer user_id (user ID registered on the site) and referrer (address of the page from which the connection was made) to the server, so that each connection can be checked for user_id and referrer?

ExchangeAssets avatar Sep 29 '23 11:09 ExchangeAssets

I use: $channel_server = new Channel\Server('0.0.0.0', 2347);

it sends messages to all users, as if I need to send messages only to users who are connected from the page mysite.com/page_1, while not sending messages to users connected from mysite.com/page_2.

It should roughly look like this:

foreach($worker->connections as $connection) {
    if($connection->get('page') != 'page_1') continue;
    $connection->send($data);
}

but how to pass 'page' in $connection when connecting? Do you have an example?

ExchangeAssets avatar Sep 29 '23 11:09 ExchangeAssets

Just use $connection->page;

walkor avatar Oct 05 '23 01:10 walkor