+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Get Version Info

  1. #1
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Get Version Info

    Hello, Xav again. In this tutorial we are going to see how to retrieve information about the version and components of your PHP installation.

    Introduction


    There are lots of different features in PHP that exist only in certain versions of PHP. For example, Object Oriented Programming (or OOP for short) was revamped in version 5, even though it has existed since PHP version 3. You can read more about PHP 5's object oriented features in Jordan's tutorial, PHP 5 and OOP.

    The strange thing is, in quite a few hosting packages, companies don't actually disclose much data about the PHP installation. For example, in my 1&1 package I had no idea which version of PHP I had installed, as the signup page simply said "PHP 4 & 5".

    Getting your PHP Version

    Thank goodness PHP has addressed this problem. There is a function called phpinfo(), which tells you your PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and, of course, the all-important PHP License. It is incredibly simple to use.

    1. Create a blank page and call it info.php. Open it in any editor of your choice and type the following code:

    Code:
    <?php

    //Echo the information page
    //to the browser.
    phpinfo();

    ?>
    And that's it! Note that phpinfo() can return a boolean value relating to the success or failure of the operation. Load the page up under your local server (or online server if you're using one) and you should see a page containing all the information you need.



    Note, however, that you can also use phpinfo() with a single parameter, $with, as well. For more info on these bit-packed constants, see PHP: phpinfo - Manual for more details.

    Just the PHP Version, please


    If you want, you can just retrieve the PHP Version on its own, without the other stuff. To do this, just use the built-in phpversion() function.

    Code:
    <?php

    echo 'I am using PHP Version ' phpversion();

    ?>
    Again, phpversion() can be used with a single parameter, this time a string argument denoting the name of the extension to the return the version for. Visit PHP: phpversion - Manual for details.

    Xav

    +rep if useful; leave any comments/queries below!
    Last edited by Xav; 08-23-2008 at 12:42 PM.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Get Version Info

    *ahem*

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  4. #3
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Get Version Info

    Very useful and simple code to know a lot about your PHP installation. I didn't actually know about phpversion() function. I like how it tells you about your execution time, and enabled extensions.

    Again great tutorial xav.

  5. #4
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Get Version Info

    Thanks.

    May I bring to your attention the very last line of my tutorial, in bold?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  6. #5
    Jordan Guest

    Re: Get Version Info

    You can also use this in CLI mode with grep for some handy info. For instance, say you wanted to find where php.ini is located (and your CLI version does not use a different php.ini than your web version) you could execute this:

    Code:
    # php -r "phpinfo();" | grep php.ini 
    replace php.ini with anything you want to search for (sorry Windows users, you'll have to browse through the HTML output).

    This tutorial is fairly short and common knowledge. None-the-less it is formated well and does provide some valuable information. +rep

  7. #6
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Get Version Info

    I'd give you some more rep, if I could. Written very well +rep coming when I can again. Nice formatting also.

  8. #7
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Get Version Info

    Cheers guys.

    @Jordan: I didn't understand anything in your post except for the very last sentence.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  9. #8
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Get Version Info

    In CLI you can also do
    Code:
    #php -v
    In PHP you can also do
    Code:
    echo PHP_VERSION 
    No sense to use a function call when there is a predefined constant that does the same thing.

  10. #9
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Get Version Info

    Erm, what's CLI mode?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  11. #10
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Get Version Info

    Erm, I have no idea.

    I got a pre-compiled server, so I have no idea.

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. div tag info
    By techker in forum JavaScript and CSS
    Replies: 4
    Last Post: 03-01-2009, 05:06 PM
  2. Replies: 0
    Last Post: 01-26-2009, 11:14 AM
  3. Replies: 1
    Last Post: 01-29-2008, 11:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts