Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get real user IP with PHP Ratchet Web socket server

I have been using PHP Ratchet with Stunnel for SSL. It's working well. But the problem is, I can't get users real IP address.

I already tried these

$conn->remoteAddress

and with this I am getting 127.0.0.1 (local address)

$conn->WebSocket->request->getHeader('X-Forwarded-For');

and with this I am getting nothing.

Any help!

like image 913
h_h Avatar asked Oct 12 '25 09:10

h_h


2 Answers

Or sometimes it's $conn->httpRequest->getHeaders()['X-Forwarded-For'][0].

like image 76
John Alexander Avatar answered Oct 14 '25 06:10

John Alexander


This is really old, but I ran into it just now.

You're looking for $conn->WebSocket->request->getHeader('x-forwarded-for) or $conn->WebSocket->request->getHeader('x-real-ip').

See $conn->WebSocket->request->getHeaders() for the entire list.

like image 44
Rian Avatar answered Oct 14 '25 05:10

Rian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!