What is an IP Address ? IP Address or Internet Protocol Address is a numerical value assigned to every device on network which uses the Internet Protocol for Communication.
An IP address serves two major functions:
- Network/Host interface identification
- Location addressing
Static IP addresses that do not change very often that are provided to servers. The ISP provides a unique IP address to a home machine that is dialing via modem, and the IP address is unique for that session and it may change the next time for the machine.
How to identify your server’s IP address: The $_SERVER is an array in PHP that contains the information regarding the headers, paths and script locations. The web server itself creates the entries of this array. Though it does not guarantee every web server will provide the contents of these arrays, servers may usually omit some of the $_SERVER array contents.
In order to obtain the IP address of the server one can use [‘SERVER_ADDR’], it returns the IP address of the server under the current script is executing.
Another method is using the [‘REMOTE_ADDR’] in the $_SERVER array. [‘REMOTE_ADDR’] is only used for getting the IP address for the local servers although the output produced will be the same as using [‘SERVER_ADDR’] for the local server IP address.
Example 1: This example identify the servers IP address using [‘SERVER_ADDR’].
Server IP Address is: ::1
Example 2: This example identify the servers IP address using [‘REMOTE_ADDR’].
Server IP Address is: ::1
Note: If you try to run the above code on any online IDE it would either return a runtime error or no output, as private domains don’t share their IP, try running on localhost or a server. For localhost, if ipv4 loopback address is used then it will give 127.0.0.1 and if ipv6 loopback address is used then it will give ::1.
- Node.js server.address() Method
- Difference Between Web server and Application server
- Difference between Apache Tomcat server and Apache web server
- PHP | Determining Client IP Address
- How to get the MAC and IP address of a connected client in PHP?
- How to Get Local IP Address of System using PHP ?
- PHP program to fetch data from localhost server database using XAMPP
- Create a web server and run PHP script on it using Raspberry Pi
- How to move a file into a different folder on the server using PHP?
- Address Calculation Sort using Hashing
- HTML | address Tag
- HTML | DOM Address Object
- Perl | Extract IP Address from a String using Regex
- How to instantiate Struct Pointer Address Operator in Golang?
- How to check if email address is already in use or not using express-validator in Node.js ?
- Node.js socket.address() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.