6

I am writing a web application with PHP and Javascript that uses Ratchet WebSockets for communication data between server and clients, but I need to get client's IP address.

In Ratchet WebSockets have a function "onOpen" that it give an object of "ConnectionInterface":

public function onOpen(ConnectionInterface $conn){ $this->clients->attach($conn); echo "new Connection is connected...({$conn->resourceId})\n"; } 

It only has a resource id. How can I get the IP address of this connection?

1

3 Answers 3

9
$conn->remoteAddress 

Try this.

Sign up to request clarification or add additional context in comments.

1 Comment

It's a shame they don't give the port though, the same client can be open multiple times over different ports
1

$conn variable contains following two fields: $conn->resourceId and $conn->remoteAddress

Reference URL

Comments

-2

Try this. $ClientIP = $_SERVER['REMOTE_ADDR']; echo $ClientIP; echos the client's IP Address 98.1.xx.x You can find the reference on $_SERVER at http://php.net/manual/en/reserved.variables.server.php

1 Comment

That's for a bog-standard HTTP request, not this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.