|
Last Change
phpinfo() creates a web page with comprehensive system environment information such as operating system and web server environment, PHP configuration, paths, global and local values of configuration options, HTTP headers, etc. Because every system is setup differently, phpinfo() is often used to check configuration settings and predefined system variables. phpinfo() is also a valuable debugging tool as it lists GET, POST, cookie, environment and server data.
It doesn't come as a surprise that the following script is often the first PHP script a PHP developer runs on a new client system:
<?php phpinfo(); ?>
The above script is usually saved under a file name such as phpinfo.php. Since phpinfo() exposes information which might help hackers to break into a system, it is not recommended to provide easy and/or permanent public access to phpinfo() scripts.
The phpversion() retrieves the current PHP version:
<?php echo '<p>PHP Version: '.phpversion().'</p>'; ?>
Output:
PHP Version: 5.6.31
The string returned by phpversion() can easily be converted to a numeric value:
<?php echo '<p>PHP Version: '.phpversion().' = '.(float)phpversion().'</p>'; ?>
Output:
PHP Version: 5.6.31 = 5.6
phpversion() can be used to control the execution of PHP functions with different implementations depending on the PHP version. The following code shows a version-independent application of the microtime() PHP function for retrieving the Unix timestamp with microseconds accuracy:
<?php
function getMicrotime()
{
// Get Unix timestamp with microseconds accuracy
if ((float)phpversion() >= 5.0)
{
return microtime(1);
}
list($usec, $sec) = explode(' ', microtime());
return ((float)$sec + (float)$usec);
}
?>
PHP Functions • © 2017 Manfred Baumeister
|