How to get IP Address of clients machine in PHP ? Last Updated : 02 Jun, 2022 Comments Improve Suggest changes Like Article Like Report An IP address is used to provide an identity to a device connected to a network. IP address stands for Internet Protocol address. An IP address allows to track the activities of a user on a website and also allows the location of different devices that are connected to the network to be pinpointed and differentiated from other devices. There are two ways to get the IP Address of the client's machine in PHP. One way is to use the $_SERVER variable and another way is by using the getenv() function. $_SERVER Variable: It fetches the IP address of the machine from which the request was sent to the webserver. It is an array created by the Apache webserver. Bypassing REMOTE_ADDR in the $_SERVER variable gives the IP address of the client. Sometimes we won't get an IP address using REMOTE_ADDR because when the user is from the proxy network, REMOTE_ADDR cannot be fetched. In this case, PHP provides two other variables HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR which are passed in $_SERVER to get an IP address. getenv() function: The other way to get the IP address of the client is using the getenv() function. It is used to retrieve the value of an environment variable in PHP. To get the IP address of the user we need to pass the REMOTE_ADDR variable to the getenv() function. Syntax:the getenv("REMOTE_ADDR");Example 1: Let us look into a sample program to fetch the client's IP address. PHP <?php // if user from the share internet if(!empty($_SERVER['HTTP_CLIENT_IP'])) { echo 'IP address = '.$_SERVER['HTTP_CLIENT_IP']; } //if user is from the proxy elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { echo 'IP address = '.$_SERVER['HTTP_X_FORWARDED_FOR']; } //if user is from the remote address else{ echo 'IP address = '.$_SERVER['REMOTE_ADDR']; } ?> Output: Your IP Address is ::1 Example 2: Below code will give the IP Address of clients machine: PHP <?php echo "IP Address of client " . getenv("REMOTE_ADDR"); ?> Output: IP Address of client ::1 Comment More infoAdvertise with us Next Article How to get IP Address of clients machine in PHP ? A akhilvasabhaktula03 Follow Improve Article Tags : Web Technologies PHP PHP-Questions Similar Reads How to get client IP address using JavaScript? Imagine your computer as your apartment. Just like each apartment has a unique address for receiving mail, your computer has an IP address that helps it receive information from the internet. This IP address acts like a label that identifies your specific device on the vast network of computers, ens 2 min read C# Program to Find the IP Address of the Machine An IP address is known as an Internet Protocol address. It is a unique address that identifies the device over the network. It is almost like a set of rules which govern the data sent over the Internet or through a local network. It helps the Internet to distinguish between routers, computers, websi 3 min read How to get Geolocation using PHP-cURL from IP Address ? Geolocation refers to the identification of the geographical location of a user or computer device. In this article, we will create a web page where the user can enter the IP Address of any device, and then the server will provide Geolocation of the IP address fetching the following details using t 2 min read How Do I Get User IP Address in Django? In web development, knowing a user's IP address can be crucial for a variety of reasons, such as logging, analytics, security, and customization. Django, a powerful web framework for Python, provides several ways to access user IP addresses. In this article, we'll walk through creating a small Djang 2 min read How to Find Your Local IP Address in Debian 11 The IP address is the specific number that identifies the devices on the network. This IP address will help the other devices to find and communicate with your device. When you connect your device to a a computer or phone to the local network such as your home and office network it immediately assig 4 min read How to Find Your IP Address? Finding your IP address is a simple but also an important task for anyone using the internet. Whether youâre troubleshooting network issues, setting up a new device, or securing your online activity, knowing your IP address is a key step.In this article, weâll show you how to find your IP address on 6 min read How to get cookies from curl into a variable in PHP ? The cURL standing for Client URL refers to a library for transferring data using various protocols supporting cookies, HTTP, FTP, IMAP, POP3, HTTPS (with SSL Certification), etc. This example will illustrate how to get cookies from a PHP cURL into a variable. The functions provide an option to set a 2 min read Determining the IP Address & Hostname of Local Computer in Java IP Address Stands for Internet Protocol Address, is a numeric label that is assigned uniquely to each device connected within a computer network that uses the internet protocol. An IP address serves two principal functions: It identifies the host, or more specifically its network interface.It provi 3 min read How to determine the user IP address using node.js ? Node.js is an open-source, back-end JavaScript runtime environment that runs on the web engine and executes JavaScript code. There are various platforms such as Windows, Linux, Mac OS  where Node.js can run. The Domain Name System is a hierarchical and decentralized naming system for computers etc t 2 min read Find All Live Hosts IP Addresses Connected on Network in Linux As network engineers or penetration testers, we need to find the live hosts on the networks. In today's guide, we are going to see how to find live hosts on the network. We are going to use the nmap tool to find the live hosts on the network.Nmap (network mapper) is an open-source command-line tool 4 min read Like