What is an IP Address?
The IP address stands for Internet Protocol Address. An IP address is used to provide an identity to a networked device.IP addresses allow the location of different digital devices that are connected to the Internet to be pinpointed and differentiated from other devices.
In this post we have discussed two different ways of determining the client IP address from a PHP script as explained below:
- 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 environmnet variable.Syntax :

<?php$ipaddress=getenv("REMOTE_ADDR") ;Echo"Your IP Address is ".$ipaddress;?>chevron_rightfilter_noneOutput :
Your IP is 127.1.1.0
-
Determining IP Address using $_SERVER Variable Method : There is another way to get the IP Address by using the $_SERVER[‘REMOTE_ADDR’] or $_SERVER[‘REMOTE_HOST’] variables. The variable in the $_SERVER array is created by the web server such as apache and those can be used in PHP.
Basically $_SERVER[‘REMOTE_ADDR’]gives the IP address from which the request was sent to the web server.Syntax :
<?php$ipaddress=$_SERVER['REMOTE_ADDR']Echo"Your IP Address is ".$ipaddress;?>chevron_rightfilter_noneOutput :
Your IP is 127.1.1.0
Recommended Posts:
- How to get client IP address using JavaScript ?
- How to get the MAC and IP address of a connected client in PHP?
- Client-Server Model
- How to get the client timezone offset in JavaScript?
- How to create a client-side image-map in HTML5 ?
- HTTP status codes | Client Error Responses
- How to detect operating system on the client machine using JavaScript ?
- How to set alternate content for users that do not support client-side scripts ?
- HTML | address Tag
- How to Get Local IP Address of System using PHP ?
- How to identify server IP address in PHP ?
- HTML | DOM Address Object
- Server side and Client side Programming
- How to check for IP address using regular expression in javascript?
- How to validate email address using RegExp in JavaScript ?
- How to check if email address is already in use or not using express-validator in Node.js ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.

