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?
Using getenv() function: To get the IP Address,we use getenv(“REMOTE_ADDR”) command. The getenv() function in PHP is used for retrieval of values of an environment variable in PHP. It is used to return the value of a specific environment variable.
In Java, you can use HttpServletRequest. getRemoteAddr() to get the client's IP address that's accessing your Java web application.
Can I Track Someone's IP Address? Yes. As long as the device is on, connected to yours and doesn't have a proxy server or VPN obscuring it, you can track the IP address. If you want to find the IP of a device you're connected to, you can use the “netstat -an” command in the command prompt.
Client IP addresses describe only the computer being used, not the user. If multiple users share the same computer, they will be indistinguishable. Many Internet service providers dynamically assign IP addresses to users when they log in.
$conn->remoteAddress
Try this.
$conn
variable contains following two fields:
$conn->resourceId
and $conn->remoteAddress
Reference URL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With