PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 5, 2022

[FIXED] How can I get the referer for a socket.io connection

 August 05, 2022     node.js, socket.io     No comments   

Issue

I have a simple node.js web server and I use socket.io.

The users can perform simple tasks on the server, which is a single page application running on /. If a user has an existing state on the server, the user's ID could be appended to the URL, e.g. /{my-id}.

I need to extract the ID from the URL when a socket.io connection is established. Is it any way to get the URL for the client page where the socket is created from; the referrer of the connection request?


Solution

Using console.log I managed to find this value like this:

io.on('connection', function (socket) {
    var referer = socket.request.headers.referer;
});

It works, but as it is not documented, I don't know if this is recommended, or if it's going to change.



Answered By - Jørgen
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing