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.
- Difference Between Web server and Application server
- HTML | address Tag
- Node.js | Web Server
- Web Server and Its Type
- PHP | Determining Client IP Address
- HTML | DOM Address Object
- How to get the MAC and IP address of a connected client in PHP?
- Client-Server Model
- HTTP headers | Server
- Difference between Web Browser and Web Server
- Address Calculation Sort using Hashing
- AWS EC2 Instance Setup with Apache Server
- How to install Apache server in Ubuntu ?
- Create a web server and run PHP script on it using Raspberry Pi
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.