phpinfo() and PHP version
Learn the server configuration with phpinfo() and the PHP_VERSION constant.
What is phpinfo()?
phpinfo() is a built-in function that displays PHP configuration information. It produces a detailed table about the version, extensions and server settings.
It is simple to use: <?php phpinfo(); ?> — write this in a file and open it on the server to see the info table.
During development it is very useful for checking which extensions are installed.
Security note: do not leave a phpinfo() page publicly accessible on a live site; it leaks server information.
The PHP_VERSION constant
PHP_VERSION is a built-in constant that holds the installed PHP version. Its value is a string like "8.3.0".
Usage: echo PHP_VERSION; — this prints the version number.
Similar constants exist: PHP_SAPI gives the server interface type (for example cli or apache2handler).
Constants are written in uppercase and do not take a $ sign.
Exercise phpinfo comment and print version
Write a PHP block. Include the word phpinfo() in a // comment. Then use echo to print "PHP 8.3"; add \n at the end of the line.
Show example solution
Write phpinfo in a // comment, then add echo "PHP 8.3\n";.
Example solution:
<?php
// phpinfo() gives configuration info
echo "PHP 8.3\n";
Test yourself
-
What does phpinfo() show?
- The browser version
- PHP errors
- Database records
- PHP configuration info
Show answer
PHP configuration info — Correct! phpinfo() shows PHP configuration info.
-
Match the PHP constants
- phpinfo()
- Configuration info
- PHP_VERSION
- Version number
- PHP_SAPI
- Server interface
-
Write the version constant
<?php echo ____; ?>Show answer
<?php echo PHP_VERSION; ?>