Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get client's IP address?

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?

like image 759
amin msh Avatar asked Sep 23 '15 00:09

amin msh


People also ask

How can we get IP address of the client?

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.

How do I get client IP from request?

In Java, you can use HttpServletRequest. getRemoteAddr() to get the client's IP address that's accessing your Java web application.

Can you look at someones IP address?

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.

Does a client have an IP address?

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.


2 Answers

$conn->remoteAddress

Try this.

like image 178
Eugene L Avatar answered Oct 23 '22 15:10

Eugene L


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

Reference URL

like image 32
mohsin.mr Avatar answered Oct 23 '22 16:10

mohsin.mr