Get users IP by Getenv() PHP Function

Definition: Getenv () is used to get the value of an environmental variable. It is written as Getenv (varname) .

Below are some examples of environmental variables you can use. If you are interested, you can see a full list by running phpinfo ().

Also Known As: Get Environment Variable

Examples:

Get users IP by getenv() function. This is useful, when you want to know the users IP of your site during registration. By this you can know about users that, from where they are signing up or related information.

You can also track users during login that, every time users are logging in and you know from which area or IP they are access your site. So see the simple use of this function:

<?php
//Gets the IP address
$ip = getenv(“REMOTE_ADDR”) ;
Echo “Your IP is ” . $ip;
?>

<?php
//Gets the document root
$root = getenv(“DOCUMENT_ROOT”) ;
Echo $root;
?>

<?php
//Gets the server admin’s email
$ad = getenv(“SERVER_ADMIN”) ;
Echo $ad;
?>

Happy’s coding 🙂

Definition: Getenv () is used to get the value of an environmental variable. It is written as Getenv (varname) ;

Advertisements