User Info with PHP

The following snippets illustrate some of the stuff PHP knows about your website visitors, e.g. the IP address or which page that let them to your page (referer). These are just some of the predefined constants/reserved variables PHP provide, see Predefined Variables.

User's IP address

<?php echo $_SERVER['REMOTE_ADDR']; ?>

Info about user's browser

<?php echo $_SERVER['HTTP_USER_AGENT']; ?>

CCBot/2.0 (

Which page did refer the user here

<?php echo $_SERVER['HTTP_REFERER']; ?>

Path to this page (with http query)

<?php echo $_SERVER['REQUEST_URI']; ?>


Path to this page

<?php echo $_SERVER['PHP_SELF']; ?>


Full server path to the website's root

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>


To see all info PHP knows create and upload a file with the following content and view it in your browser (remember to delete it again after).


<?php phpinfo(); ?>

Geo Location

An user's IP tells in which country and region the user is located (approximately and not accounting for VPN connections or proxy servers). This information can be used to display the website in a specific language, use local currency, or provide other locally relevant info. One of many geo location providers is and as example using your IP ( request

<?php echo file_get_contents('url as below'); ?>