PHP Version

12 12 2011

The PHP logo displaying the Handel Gothic font.

Image via Wikipedia

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:

phpinfo();

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:

?=PHPE9568F36-D428-11d2-A769-00AA001ACF42

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:

http://drupal.org/node/243993

http://php.net/manual/en/function.phpversion.php

http://www.php.net/manual/en/reserved.constants.php#reserved.constants.core

http://www.sitepoint.com/phps-doggie-easter-egg/


Actions

Information

11 responses

7 01 2012
itoctopus

I don’t understand why you have to write this whole routine to check if phpinfo works or not. If phpinfo works, then it’ll display something, otherwise, it won’t.

Thanks for the easter egg, I tried it, and it just showed the php logo (it’s nice though).

8 01 2012
Sharon Lee Levy

There are any number of reasons why you might see a blank screen. By using the first snippet that I provide, you get the certainty of knowing precisely why you have a blank screen which in this particular instance proves that it’s because phpinfo() is disabled.

9 01 2012
Sharon Levy Blog: PHP Version | PHP Boutique

[…] mit ist gekommen, um die PHP-Version Informationen (in der Regel in der gefunden zeigen phpinfo ) auch wenn es deaktiviert ist . Manchmal sind die wichtigsten, grundlegenden Teil der Information kann scheinen so schwer zu […]

17 02 2013
http://community.lawyers.com/members/735672/default.aspx

I’ve read some good stuff here. Definitely worth bookmarking for revisiting. I wonder how much effort you put to make this kind of wonderful informative web site.

25 02 2013
Sharon Lee Levy

Thanks — I’m glad you like my blog. I strive to write articles that visitors will find useful.

18 02 2013
Side Table Plans

Very good blog you have here but I was curious about if you knew of
any discussion boards that cover the same topics discussed here?
I’d really like to be a part of group where I can get advice from other experienced individuals that share the same interest. If you have any recommendations, please let me know. Appreciate it!

20 02 2013
Sharon Lee Levy

I’m glad you like my blog. As for discussion boards, I’d recommend that you may wish to join one of the mailing lists at http://www.php.net. Or, alternatively, if there is a local PHP Meetup out your way that would be another option.

22 02 2013
asahtpj86

I think the admin of this site is actually working hard in support of his site, for the reason that here every information is quality based information.

25 02 2013
Sharon Lee Levy

Thank you for your kind words and appreciating my effort. Note,the admin, i.e. myself, is a “she” rather than a “he”.

18 03 2013
Sharon Lee Levy

A remote image becomes unavailable occasionally when a photographer decides to make their images not freely available. When that happens, please let me know which image is failing to display so I may replace it. There could be many other reasons for images not loading. See http://help.yahoo.com/kb/index?locale=en_US&y=PROD_ACCT&page=content&id=SLN3699 for possible issues that could be interfering with your browsing experience.

21 10 2014
Programowanie w PHP » Blog Archive » Sharon Levy’s Blog: PHP Version

[…] Sharon Levy has a new post to her blog showing a trick she’s come up with to show the PHP version information (usually found in the phpinfo) even when it’s disabled. […]

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.