How to reveal Magento version by code?

The Mage::getVersion() method is defined here

#File: app/Mage.php
public static function getVersion()
{
    $i = self::getVersionInfo();
    return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "")
                    . "-{$i['stability']}{$i['number']}", '.-');
}

Jumping to the getVersionInfo referenced above, we find the following

#File: app/Mage.php
public static function getVersionInfo()
{
    return array(
        'major'     => '1',
        'minor'     => '7',
        'revision'  => '0',
        'patch'     => '2',
        'stability' => '',
        'number'    => '',
    );
}

So, Magento uses the array returned by the getVersionInfo method to come up with a version number. We can do so manually (with our minds), and come up with the version 1.7.0.2 for the method listed above. If we found

public static function getVersionInfo()
{
    return array(
        'major'     => '1',
        'minor'     => '5',
        'revision'  => '0',
        'patch'     => '0',
        'stability' => 'beta',
        'number'    => '1',
    );
}

We'd know the version was the 1st beta of 1.5.0.0.

That said, if the site's been hacked, all bets are off — as hackers have likely modified multiple class files and create a version of Magento that doesn't exist.


if hacked then you need to restore backup, and then you can run this command from magento root folder to check version quickly:

echo "Version: $(php -r "require 'app/Mage.php'; echo Mage::getVersion();")"

Version: 1.9.2.3

or even quicker:

grep -A 10 "function getVersionInfo" app/Mage.php 

public static function getVersionInfo()
{
    return array(
        'major'     => '1',
        'minor'     => '9',
        'revision'  => '2',
        'patch'     => '3',
        'stability' => '',
        'number'    => '',
    );
}

We can find the magento which version is using now easily.

Just open your root folder /app/Mage.php

Near 168 line, you can find following code

public static function getVersionInfo()

{

    return array(

        'major'     => '1',

        'minor'     => '9',

        'revision'  => '0',

        'patch'     => '1',

        'stability' => '',

        'number'    => '',

    );

} 

It means that we are currently using 1.9.0.1 version.