O
O
OneTwoThreeFourFive2021-11-07 20:58:58
WordPress
OneTwoThreeFourFive, 2021-11-07 20:58:58

Authorization when connecting to websocket and wordpress cookies?

You need to add messages between users to the site on wordpress using websocket. Used by Workerman. The user's cookies cannot be retrieved because the $_COOKIE array is empty (cookies are not passed over the websocket).

Wordpress uses the httponly flag and cookie values ​​cannot be retrieved using js.

Is it safe to send an ajax request when loading the page and receive cookies in response from the server, and pass the cookie values ​​​​to the websocket. On the websocket server, get the user id using a function wp_validate_auth_cookieand specify the value in the connection data.

It looks weird but no time for node js. Need a php solution.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question