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']; ?>


2600:1f28:365:80b0:b2d8:c007:49fc:9498

Info about user's browser

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


CCBot/2.0 (https://commoncrawl.org/faq/)

Which page did refer the user here

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


Path to this page (with http query)

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


/docs/scripts/userinfo.php

Path to this page

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


/docs/scripts/userinfo.php

Full server path to the website's root

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


/customers/f/f/3/cozm1zehn/webroots/www

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).

phpinfo.php

<?php phpinfo(); ?>