Sometimes the most crucial, basic piece of information can seem so hard to find. For example, suppose you wanted to find out what version of PHP your remote webhost provides to shared hosting users? What would you do? You may smugly reply, “phpinfo()”. That is certainly a viable option on your localbox but what about at the live site? Years ago a lot of PHP users thought nothing of having a simple phpinfo.php file that looked like this:
That simple one-line command would dump a whole ton of info on a user’s screen, most of which was far more than most users even wanted, let alone comprehended. Most of us certainly didn’t understand that there were potential security issues in making all that information available for anyone to see.
For development purposes it can be helpful having phpinfo() available, but on a live shared host, you may discover as I did recently that it is no longer available; your host may have disabled it. If you run the above script and you get nothing but a blank white page, you may want to confirm for a fact that the command is no longer available to you. You can use PHP’s Reflection Extension and write a script like the following:
echo 'is phpinfo() now disabled? '; $refFunc = new ReflectionFunction('phpinfo'); echo $refFunc->isDisabled(); // 1 means disabled
Of course, if you have Telnet access (highly unlikely if it is not your own box!) or SSH privileges, then you could use either of the following commands in CLI mode:
php -v (short syntax) php --version (longer form)
“But, isn’t there another way, one with a web interface?”, you may wonder. The good news is that yes, there is — actually two ways, as follows:
// web interface: echo nl2br("\n"),phpversion(); // alternate echo nl2br("\n"),PHP_VERSION;
You might think that’s it, but actually there is another fun (i.e. phun) way involving “Easter” eggs. It is also a bit imprecise as one icon may refer to more than one version of PHP. In general if you append a query string such as the following to any php url:
provided that there is no secruity in place to interfere, the resulting page will show a symbol that corresponds to a php version or a range of versions. However, if the ini directive expose_php is set to off, then the above trick will be disabled.
links of interest: