What is phpinfo?

phpinfo is one of the most handy functions a PHP programmer needs to know about, especially when it comes time to debugging! As the name says, phpinfo displays information about PHP.

As well as information about a particular PHP installation and configuration, it displays information on Apache, MySQL, all varieties of modules and libraries just to name a few. You can use phpinfo to check your system configuration and variables as well as your environment variables like GET, POST, Cookie and Server. phpinfo is commonly used to gather information when debugging, but it can be used for much more.

In it’s simplest form, the phpinfo function can be used like this:

< ?php // Display everything (this is the default) phpinfo (); ?>

Please note: It is usually good practice to keep this kind of information from being publicly available.

By default, a lot of information is displayed, however it is possible to display only certain information.

Here are the various parameters you can pass to phpinfo():

* INFO_GENERAL 1 The configuration line, php.ini location, build date, Web Server, System and more.
* INFO_CREDITS 2 PHP 4 Credits. See also phpcredits().
* INFO_CONFIGURATION 4 Current Local and Master values for PHP directives. See also ini_get().
* INFO_MODULES 8 Loaded modules and their respective settings. See also get_loaded_modules().
* INFO_ENVIRONMENT 16 Environment Variable information that’s also available in $_ENV.
* INFO_VARIABLES 32 Shows all predefined variables from EGPCS (Environment, GET, POST, Cookie, Server).
* INFO_LICENSE 64 PHP License information. See also the license faq.
* INFO_ALL -1 Shows all of the above. This is the default value.

Here’s how you’d go about getting information on only your environment variables:

< ?php // Display everything (this is the default) phpinfo(INFO_ENVIRONMENT); ?>

Other possible uses for phpinfo()

Troubleshooting/Support Script – Some of the information displayed by phpinfo can be very important in diagnosing problems with web applications. For example, you could easily create a script to email phpinfo results with a support ticket.

Installation Script – If you are building an install script to configure your application, you could use information from phpinfo to obtain information to assist the user.

You can find out more about phpinfo() using the online PHP User Manual.